Fix multi-embed cache dependency losing all but the last child#177
Conversation
A #[Cacheable] resource that embeds more than one child (DiamondTop embeds both DiamondLeft and DiamondRight, which both embed the shared DiamondBottom) is not handled: CacheDependency::depends() overwrites the parent's Surrogate-Key and asserts the parent has none yet. The build aborts (assertion) / loses all but the last child's dependency, so this test currently FAILS — it documents the bug before the fix in the next commit.
CacheDependency::depends() overwrote the parent's Surrogate-Key (and asserted the parent had none yet), so a #[Cacheable] resource that embeds more than one child kept only the LAST child's dependency. Purging an earlier child then failed to invalidate the parent, which kept serving a stale page (under-invalidation); with assertions enabled it threw instead and the page was not cached at all. Accumulate the child tags across every embedded child and drop the assertion. Turns the diamond-dependency test from the previous commit green.
|
@coderabbitai review |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR fixes a cache invalidation bug where ChangesCache Dependency Accumulation Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
✅ Actions performedReview triggered.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.x #177 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 246 247 +1
===========================================
Files 53 53
Lines 750 749 -1
===========================================
- Hits 750 749 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
概要 / Summary
#[Cacheable]なリソースが複数の子リソースを埋め込む場合に、親リソースのキャッシュ依存関係が正しく保持されない不具合を修正します。This fixes a bug where cache dependencies were not preserved correctly when a
#[Cacheable]resource embedded multiple child resources.これまで
CacheDependency::depends()は、子リソースのタグを追加するたびに親リソースのSurrogate-Keyヘッダーを上書きしていました。そのため、複数の子を持つ親リソースでは最後に処理された子の依存関係だけが残り、それ以前の子リソースを purge / refresh しても親リソースが無効化されませんでした。Previously,
CacheDependency::depends()overwrote the parent'sSurrogate-Keyheader on each child dependency, so only the last child dependency was retained.発生条件 / Condition
この不具合は、キャッシュされる親リソースが複数の cacheable な子リソースを embed している場合に発生します。
This bug occurs when a cached parent resource embeds multiple cacheable child resources.
実装上は、embed された子リソースを materialize した後、その子が
ETagヘッダーを持つ場合だけ依存関係を登録します。非 cacheable な embed はETagを持たないため、この依存関係登録の対象外です。In implementation terms, dependency registration only happens when the embedded child has an
ETagheader. Non-cacheable embedded resources are not part of this dependency graph.影響 / Impact
depends()呼び出しでAssertionErrorが発生し、キャッシュ処理が失敗する可能性がありました。depends()call could fail with anAssertionError.修正内容 / Fix
CacheDependency::depends()で、親リソースの既存のSurrogate-Keyに子リソースのタグを蓄積するように変更しました。CacheDependency::depends()now accumulates child tags into the parent's existingSurrogate-Key.テスト / Tests
追加した
ComplexCacheDependencyTestで以下を確認しています。ComplexCacheDependencyTestverifies:DiamondTopがDiamondLeft/DiamondRight/DiamondBottomを含む全依存タグを保持することDiamondTopretains dependency tags forDiamondLeft,DiamondRight, andDiamondBottom.DiamondBottomを purge すると、親のDiamondTopも正しく無効化されることDiamondBottomcorrectly invalidates parentDiamondTop.DiamondLeftまたはDiamondRightを個別に purge しても、親のDiamondTopが正しく無効化されることDiamondLeftorDiamondRightalso invalidatesDiamondTop.AI を活用して、単一 embed の既存 fixture では見落としやすい複雑な条件を洗い出し、複数 child・共有 dependency・個別 purge・rebuild 後の再伝播を検証するテストを追加しました。これにより、今回の修正だけでなく今後の回帰検出の信頼性も高めています。
AI-assisted test exploration was used to add complex dependency scenarios covering multiple children, shared dependencies, selective purges, and dependency propagation after rebuilds. This improves confidence in the fix and future regression detection.
品質チェック結果 / Quality checks:
いずれもエラーなしです。
All checks passed.