Skip to content

Add configurable identity cache TTL (refresh stale names/avatars)#2

Closed
Frodotus wants to merge 3 commits into
identity-ttl-review-basefrom
feat/identity-ttl
Closed

Add configurable identity cache TTL (refresh stale names/avatars)#2
Frodotus wants to merge 3 commits into
identity-ttl-review-basefrom
feat/identity-ttl

Conversation

@Frodotus

Copy link
Copy Markdown
Owner

Internal review copy of upstream PR gammons#79 — opened to get a Copilot review.

What

Adds [cache] identity_ttl_days (default 7; 0 = cache forever) so resolved user/bot identities (name + avatar) are re-fetched once stale instead of cached forever.

How

  • CacheConfig.IdentityTTLDays; UpsertUser stamps updated_at so freshness is tracked.
  • userResolver gains a TTL: Request/RequestBot skip only when cached and fresh; past the TTL they re-fetch (users.info/bots.info).
  • Avatar refresh busts the inflight gate, the cached render, and the fetcher's avatar-<id> entry so a changed URL re-downloads.

Testing

go test ./... passes. TestUserResolverFresh (TTL decision incl. 0=off, unstamped=stale) + TestUpsertUserStampsUpdatedAt.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable TTL for cached Slack user/bot identities so display names and avatars are periodically re-resolved instead of being cached indefinitely, including invalidation of avatar render and image-cache entries when refreshed.

Changes:

  • Introduces [cache] identity_ttl_days config (default 7; 0 disables refresh) and wires it into workspace user resolution.
  • Stamps users.updated_at on UpsertUser to track identity freshness, and refreshes identities past the TTL.
  • Adds avatar/image-cache invalidation support and new tests covering TTL freshness + updated_at stamping.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
wiki/Configuration.md Documents new identity_ttl_days cache option.
internal/image/fetcher.go Adds a Fetcher.Delete helper to evict cached image entries by key.
internal/config/config.go Adds CacheConfig.IdentityTTLDays with default value.
internal/cache/users.go Stamps updated_at on UpsertUser when unset to enable TTL freshness checks.
internal/cache/users_ttl_test.go Adds tests verifying updated_at stamping behavior.
internal/avatar/avatar.go Adds avatar.Cache.Invalidate to force re-fetch/re-render of avatars on refresh.
cmd/slk/main.go Adds TTL-aware freshness logic to userResolver and passes configured TTL duration.
cmd/slk/identity_ttl_test.go Adds unit test for resolver TTL freshness behavior (including ttl=0 and unstamped rows).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/image/fetcher.go Outdated
Comment on lines +150 to +156
// fallback auths are tried for foreign-team URLs (Slack Connect).
// Safe to call once at startup; not safe to mutate the input slice
// afterward.
// Delete evicts a cached entry by key, forcing the next Fetch for that
Comment thread cmd/slk/main.go Outdated
p.Send(msg)
}
},
time.Duration(cfg.Cache.IdentityTTLDays)*24*time.Hour,
Comment thread internal/cache/users_ttl_test.go
Comment thread internal/cache/users_ttl_test.go Outdated
…nts, clamp negative TTL, close test DB + check GetUser error)
@Frodotus

Copy link
Copy Markdown
Owner Author

Thanks @copilot — all four addressed in the latest push:

  1. fetcher.go — moved Delete below SetAuths so each has its own GoDoc comment immediately above it (the SetAuths doc no longer attaches to Delete).
  2. main.go — clamp the identity TTL to 0 for negative config values (if identityTTL < 0 { identityTTL = 0 }), so an accidental negative no longer silently means "never refresh" by coincidence; it's now explicit.
  3. users_ttl_test.go — added defer db.Close().
  4. users_ttl_test.go — the GetUser("U2") error is now checked with t.Fatalf.

Build + full suite green.

@Frodotus Frodotus deleted the branch identity-ttl-review-base June 11, 2026 14:03
@Frodotus Frodotus closed this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants