Add configurable identity cache TTL (refresh stale names/avatars)#2
Closed
Frodotus wants to merge 3 commits into
Closed
Add configurable identity cache TTL (refresh stale names/avatars)#2Frodotus wants to merge 3 commits into
Frodotus wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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_daysconfig (default 7;0disables refresh) and wires it into workspace user resolution. - Stamps
users.updated_atonUpsertUserto track identity freshness, and refreshes identities past the TTL. - Adds avatar/image-cache invalidation support and new tests covering TTL freshness +
updated_atstamping.
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 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 |
| p.Send(msg) | ||
| } | ||
| }, | ||
| time.Duration(cfg.Cache.IdentityTTLDays)*24*time.Hour, |
…nts, clamp negative TTL, close test DB + check GetUser error)
Owner
Author
|
Thanks @copilot — all four addressed in the latest push:
Build + full suite green. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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;UpsertUserstampsupdated_atso freshness is tracked.userResolvergains a TTL:Request/RequestBotskip only when cached and fresh; past the TTL they re-fetch (users.info/bots.info).avatar-<id>entry so a changed URL re-downloads.Testing
go test ./...passes.TestUserResolverFresh(TTL decision incl.0=off, unstamped=stale) +TestUpsertUserStampsUpdatedAt.