perf: replace Redis KEYS with SCAN for cache invalidation (#98) #101
No reviewers
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#101
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/major-domo-v2-98"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #98
Summary
Replace the blocking
KEYScommand with non-blockingSCANiteration inCacheManager.clear_prefix().Before:
After:
KEYSblocks the Redis server for its full duration;scan_iteriterates incrementally and non-blocking.Files Changed
utils/cache.py—CacheManager.clear_prefix()lines 190–194Test Results
958 passed, 2 skipped
AI Code Review
Files Reviewed
utils/cache.py(modified)Findings
Correctness
scan_iter(match=pattern)call is the correct async API onredis.asyncio. It returns anAsyncIterator[bytes]and thematch=keyword argument is the right parameter name — no issues there.keys+deleteflow. Thedeletedvariable still receives the return value ofclient.delete(*keys_to_delete)and is passed to the logger — unchanged behavior on this path.keys_to_deletestays[], theif keys_to_delete:block is skipped, and the function falls through toreturn 0at line 199 — identical to the oldif keys:guard.scan_iteris a method on the sameredis.asyncio.Redisclient already in use.Security
prefixparameter comes from internal call sites (decorator arguments), not from user input, so there is no pattern injection concern.Style & Conventions
keys_to_deleteis clear and unambiguous.tryblock are touched.Suggestions
DELETE. For the typical key counts in this league bot this is fine, but if the keyspace ever grows very large a pipeline-based approach (delete in chunks of e.g. 100 during the scan) would reduce peak memory. Not a concern for the current use case.test_utils_cache.pycoveringCacheManager.clear_prefix()— this is a pre-existing gap not introduced by this PR. The PR body confirms 958 tests pass with no regressions. Adding unit tests for this method in a follow-up would be worthwhile.Verdict: APPROVED
The change is correct, minimal, and accomplishes exactly what it claims: replacing the blocking
KEYScommand with non-blockingSCANiteration. No logic, error handling, or return-value behavior changes. Safe to merge.Automated review by Claude PR Reviewer