Deduplicate surrogate keys when concatenating with manually-set header#176
Deduplicate surrogate keys when concatenating with manually-set header#176koriym wants to merge 1 commit into
Conversation
setSurrogateHeader() applied array_unique() only to the internally generated keys. When the ResourceObject already had a manually-set Surrogate-Key header, the keys were simply concatenated, leaving duplicates between the manual and internal sets. This happens when a parent and its embedded child share a common tag: the child's tag is merged into the internal collection and then concatenated with the parent's manual header, producing duplicates. Build the full key set first and apply array_unique() once, so manual and internal keys are deduplicated consistently. Duplicates are harmless to purging but bloat the header, risking purge misses on CDNs that cap header length. Also add /.phpunit.cache/ to .gitignore (PHPUnit's cacheDirectory), which did not match the stale /.phpunit-cache/ entry. Fixes #175
|
@coderabbitai review |
📝 WalkthroughWalkthroughThis PR fixes surrogate key deduplication in ChangesSurrogate Key Deduplication
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 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 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 |
✅ Actions performedReview triggered.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.x #176 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 246 246
===========================================
Files 53 53
Lines 750 748 -2
===========================================
- Hits 750 748 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.gitignore (1)
10-10: 💤 Low valueConsider removing the stale hyphenated pattern.
Since the PR objectives note that the hyphenated version was "stale" and line 11 now provides the correct pattern matching
phpunit.xml.dist, you may want to remove this obsolete entry to avoid confusion.🧹 Proposed cleanup
-/.phpunit-cache/ /.phpunit.cache/🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.gitignore at line 10, Remove the stale hyphenated .gitignore entry "/.phpunit-cache/" from the file; locate the obsolete pattern "/.phpunit-cache/" and delete it so only the corrected pattern (the phpunit.xml.dist-related entry mentioned in the PR) remains, avoiding redundant/obsolete ignore rules.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.gitignore:
- Line 10: Remove the stale hyphenated .gitignore entry "/.phpunit-cache/" from
the file; locate the obsolete pattern "/.phpunit-cache/" and delete it so only
the corrected pattern (the phpunit.xml.dist-related entry mentioned in the PR)
remains, avoiding redundant/obsolete ignore rules.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a8fe44eb-1b8d-48f1-9e5e-62b72f72908b
📒 Files selected for processing (3)
.gitignoresrc/SurrogateKeys.phptests/SurrogateKeysTest.php
Problem
SurrogateKeys::setSurrogateHeader()appliedarray_unique()only to the internally generated keys. When theResourceObjectalready had a manually-setSurrogate-Keyheader, the keys were simply concatenated with.=, leaving duplicates between the manual set and the internal set.This happens when a parent resource and its embedded child share a common tag (e.g. a site-wide purge tag): the child's tag is merged into the internal collection via
addTag(), then concatenated with the parent's manually-set header, producing duplicates.The result is functionally correct — Surrogate-Key is an unordered token set and purging is idempotent, so duplicates never cause wrong purges. But it is an inconsistency (internal keys are deduplicated, the concatenation is not), and the bloat is a latent risk on CDNs that cap header length, where truncation could drop tags and cause purge misses. The more embeds, the larger the header.
Fixes #175
Change
Build the full key set first, then apply
array_unique()once, so manual and internal keys are deduplicated consistently. The manual-key-first ordering is preserved (existingtestSetSurrogateHeaderexpectation is unchanged).Also
Add
/.phpunit.cache/to.gitignore.phpunit.xml.distusescacheDirectory=".phpunit.cache", which did not match the stale/.phpunit-cache/(hyphen) entry, so the cache directory was left untracked.Checks
composer cs-fixcomposer test