Cache missing Halcyon templates as a cache hit - #249
austinderrick wants to merge 2 commits into
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughThe cache callback converts a null result from Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The supplied review identifies no issue that needs correction before merging; normal checks still apply. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Missing templates can now be served from cache instead of repeatedly read from storage. The reviewed lookup still validates template names, and the new tests cover recovery when a template is created. No introduced security issue was established, although cache isolation in shared deployments remains unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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 |
Halcyon\Builder::getCached()stores query results withremember()/rememberForever(). When a single template does not exist, the stored result isnull, and the cache repository treats a storednullas a miss. Every cached lookup of a missing template therefore reads the cache store twice (has(), thenget()), asks the datasource for the file again, and writes the cache entry again. This happens on every request.The CMS hits this path on every component partial render.
ComponentPartial::loadOverrideCached()checks the theme for an override under two names (the lowercase alias and the exact alias), and most components have no override. A page with many component partials does hundreds of these lookups.To repair, I've adjusted
getCacheCallback()to store an empty result ([]) instead ofnullwhen the template is not found.An empty array already means "no records" everywhere
getCached()is used.Builder::get()does$results ?: [],and
isCacheBusted()treats an empty result as "no mtime". No other code changes.When is it
null?Only for a single-template lookup (
find()/whereFileName(), which setsselectSingle) when the template does not exist.getFresh()then callsProcessor::processSelectOne(), which returnsnullwhenever the datasource'sselectOne()does:FileDatasourcewhen the file cannot be read, andDbDatasourcewhen no row matches. Multi-record queries (get()without a file name) return[]and are already cached correctly.Tests
tests/Halcyon/HalcyonCacheTest.phpadds three tests:flushed to simulate a new request. Without the fix, this test fails with 3 datasource reads instead of 1.
Summary by CodeRabbit
Bug Fixes
Tests