Release/craft5 optimize purge strategy#3
Release/craft5 optimize purge strategy#3arontseggai wants to merge 1 commit intorelease/craft5-with-akamai-driver-supportfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Optimizes cache tag collection and purge behavior for nested/block elements in the Craft 5 plugin by targeting only the root owner’s element tag and removing section-level purges for nested content.
Changes:
- Frontend tag collection: nested elements now add only the root owner’s element-id tag and skip adding nested/child tags.
- Purge logic: nested element updates now purge only the root owner’s element-id tag (removing the extra section-level purge).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Nested elements inherit the root owner's entry tag | ||
| $rootOwner = $event->element->getRootOwner(); | ||
| if ($rootOwner !== null && $rootOwner !== $event->element) { | ||
| Plugin::getInstance()->getTagCollection()->add( | ||
| Plugin::TAG_PREFIX_ELEMENT . $rootOwner->getId() | ||
| ); |
There was a problem hiding this comment.
The comment says “root owner's entry tag”, but the code is adding an element tag using the element prefix (TAG_PREFIX_ELEMENT) and the owner’s ID. Please adjust the wording to avoid confusion about what tag format is being emitted (and that the root owner may not always be an Entry).
| // For nested elements (blocks), purge only the root owner's entry tag | ||
| $rootOwner = $event->element->getRootOwner(); | ||
| if ($rootOwner !== $event->element) { | ||
| if (isset($rootOwner->sectionId)) { | ||
| $tags[] = Plugin::TAG_PREFIX_SECTION . $rootOwner->sectionId; | ||
| } | ||
| if ($rootOwner !== null && $rootOwner !== $event->element) { | ||
| $tags[] = Plugin::TAG_PREFIX_ELEMENT . $rootOwner->getId(); | ||
| } | ||
|
|
||
| if (Plugin::getInstance()->getSettings()->isCachableElement(get_class($event->element))) { | ||
| } elseif (Plugin::getInstance()->getSettings()->isCachableElement(get_class($event->element))) { |
There was a problem hiding this comment.
This comment describes purging the “root owner's entry tag”, but the tag being purged is an element-ID tag (TAG_PREFIX_ELEMENT + ID). Consider updating the comment to reflect the actual tag format and avoid implying it is entry-specific.
| // Nested elements inherit the root owner's entry tag | ||
| $rootOwner = $event->element->getRootOwner(); | ||
| if ($rootOwner !== null && $rootOwner !== $event->element) { | ||
| Plugin::getInstance()->getTagCollection()->add( | ||
| Plugin::TAG_PREFIX_ELEMENT . $rootOwner->getId() | ||
| ); | ||
| return; | ||
| } |
There was a problem hiding this comment.
In this early-return path, tags are added via TagCollection::add() but TagCollection uniqueness is only enforced by addTagsFromElement() (which calls unique()). This can introduce duplicate root-owner tags when multiple nested elements are populated, inflating the tag header and increasing the chance of truncation. Consider ensuring the collection is de-duplicated after adding the root-owner tag (e.g., expose a public unique/dedup method or add a dedicated addUnique helper).
✅ Fix implemented