perf: skip unused variant hashes when purging cached documents - #960
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe cache-key API now separates base keys from selection-aware hashes. Document purging uses base keys to invalidate cached variants. Tests cover scoped key consistency, fresh reads after purge, variant removal, and stale lease rejection. ChangesCache purge key handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Document cache purges now avoid unnecessary selection-hash work while retaining scoped key behavior and invalidating cached variants. No concrete current-head merge risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR avoids computing an unused document-variant hash during cache invalidation while preserving the existing cache-key scope and purge operations.
Confidence Score: 5/5The PR appears safe to merge because it preserves cache-key construction and invalidation behavior while removing only unused computation. Document reads and purges continue to share identical collection and document base keys, and the existing two purge operations and their arguments are unchanged; no concrete regression remains. Important Files Changed
Reviews (1): Last reviewed commit: "refactor: separate base cache keys from ..." | Re-trigger Greptile |
Document purges currently compute a selection/filter variant hash and immediately discard it. Extract
getCacheBaseKeys()for the collection/document keys and call it directly frompurgeCachedDocumentInternal(), skipping filter-signature assembly, sorting, JSON encoding and MD5 on every document invalidation.getCacheKeys()keeps its existing signature and three-key result, usinggetCacheBaseKeys()before computing the variant hash. Purges retain the hostname/namespace/tenant/global-collection key logic and both cache purge calls, including invalidation of every document variant and its cache leases.Validation:
git diff --checkpass.purgeCachedDocument()calls against Memory/None adapters: median 301.90 ms before, 72.60 ms after (76.0% reduction). This measures PHP overhead only, not Redis latency or end-to-end production CPU savings.Motivation: fresh Cloud 1.50.6 samples showed cache-key generation in 6.5–9.0% of non-scheduler samples across API, database and usage workers. These are wall-stack samples, not on-CPU attribution; only the purge subset benefits here. No production changes or Redis-backed E2E drill were performed for this PR; lease coverage uses the existing generation-aware in-memory cache adapter.
Summary by CodeRabbit
Bug Fixes
Tests