You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(ownership): Migrate issue owners cache invalidation to use timestamp versioning on ownership (#106108)
We've been seeing [some
timeouts](https://sentry.sentry.io/issues/6731345393/?project=1&referrer=Linear)
in the `code_owners_auto_sync` task since it performs expensive O(n)
cache invalidation. When CODEOWNERS or ownership rules changed, we would
previously:
1. Query all groups in the project with recent events
2. Delete the issue owners debounce cache entry for each group
individually (via batched `cache.delete_many`)
The solution implemented in this PR is to replace this expensive fan-out
cache invalidation with an O(1) timestamp-based versioning system on
ownership schemas.
**Before**:
- Issue owners debounce cache simply stored `True` for each group
- On ownership change: delete cache entries for ALL active groups in the
project
**After**:
- Issue owners debounce cache stores the timestamp of when owners were
last evaluated for the group
- On ownership change: set a cache value with a project-wide
`ownership_changed_at` timestamp
- On debounce check:
- If `issue_owners_debounce_time` is None --> no debounce, evaluate
ownership
- If `issue_owners_debounce_time` is True --> legacy cache value,
debounce (will disappear from cache 24hrs after this PR is rolled out,
and then this logic can be removed)
- If `issue_owners_debounce_time` is a timestamp --> compare timestamps
- If `ownership_changed_at` is None or `ownership_changed_at` <
`issue_owners_debounce_time` --> debounce
- If `ownership_changed_at` >= `issue_owners_debounce_time` -->
ownership rules changed in the interim, evaluate ownership
### Follow-up
Left TODOs for both of these in the code:
- Remove backwards compatibility logic for `True` cache values 24 hrs
after this PR is rolled out
- Investigate applying same O(1) cache invalidation pattern to
`invalidate_assignee_exists_cache`
# Debounce check with timestamp-based invalidation:
257
+
# - issue_owners_debounce_time is None: no debounce, process ownership
258
+
# - issue_owners_debounce_time is True: legacy format, debounce (backwards compatibility)
259
+
# - issue_owners_debounce_time is float: compare timestamps
260
+
# - If ownership_changed_at is None or ownership_changed_at < issue_owners_debounce_time: debounce
261
+
# - If ownership_changed_at >= issue_owners_debounce_time: ownership rules changed, re-evaluate
262
+
ifissue_owners_debounce_timeisnotNone:
263
+
# TODO(shashank): once rolled out for 24hrs, remove this legacy cache format check and the comment line above. prob will need to remove some tests in test_post_process.py as well.
264
+
ifissue_owners_debounce_timeisTrue:
265
+
# Backwards compatibility: old cache format, debounce
0 commit comments