Skip to content

Release/craft5 optimize purge strategy#3

Open
arontseggai wants to merge 1 commit intorelease/craft5-with-akamai-driver-supportfrom
release/craft5-optimize-purge-strategy
Open

Release/craft5 optimize purge strategy#3
arontseggai wants to merge 1 commit intorelease/craft5-with-akamai-driver-supportfrom
release/craft5-optimize-purge-strategy

Conversation

@arontseggai
Copy link
Copy Markdown
Contributor

✅ Fix implemented

  • Nested/block element changes now purge only the owning entry tag.
  • Separate child/block tags are no longer added for purge or page tagging.
  • The previous extra section-level purge for nested content was removed.

@arontseggai arontseggai changed the base branch from release/craft3-with-akamai-driver-support to release/craft5-with-akamai-driver-support April 9, 2026 11:02
@arontseggai arontseggai requested a review from Copilot April 9, 2026 11:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/EventRegistrar.php
Comment on lines +88 to +93
// 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()
);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread src/EventRegistrar.php
Comment on lines +231 to +235
// 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))) {
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/EventRegistrar.php
Comment on lines +88 to +95
// 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;
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants