-
Notifications
You must be signed in to change notification settings - Fork 1
Release/craft5 optimize purge strategy #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/craft5-with-akamai-driver-support
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ public static function registerUpdateEvents() | |
| Event::on(Structures::class, Structures::EVENT_AFTER_MOVE_ELEMENT, function ($event) { | ||
| static::handleUpdateEvent($event); | ||
| }); | ||
| Event::on( Entries::class, Entries::EVENT_AFTER_SAVE_SECTION, function ($event) { | ||
| Event::on(Entries::class, Entries::EVENT_AFTER_SAVE_SECTION, function ($event) { | ||
| static::handleUpdateEvent($event); | ||
| }); | ||
| } | ||
|
|
@@ -85,7 +85,16 @@ public static function registerFrontendEvents() | |
| Plugin::getInstance()->getTagCollection()->add($event->element->handle); | ||
| } | ||
|
|
||
| // Add to collection | ||
| // 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; | ||
| } | ||
|
Comment on lines
+88
to
+95
|
||
|
|
||
| // Add top-level element tags to the collection | ||
| Plugin::getInstance()->getTagCollection()->addTagsFromElement($event->row); | ||
| }); | ||
|
|
||
|
|
@@ -137,7 +146,6 @@ public static function registerFrontendEvents() | |
| }); | ||
| } | ||
|
|
||
|
|
||
| public static function registerCpEvents() | ||
| { | ||
| // Register cache purge checkbox | ||
|
|
@@ -157,7 +165,6 @@ function (RegisterCacheOptionsEvent $event) { | |
| ); | ||
| } | ||
|
|
||
|
|
||
| public static function registerFallback() | ||
| { | ||
|
|
||
|
|
@@ -202,15 +209,13 @@ public static function registerFallback() | |
| }); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @param \yii\base\Event $event | ||
| */ | ||
| protected static function handleUpdateEvent(Event $event) | ||
| { | ||
| $tags = []; | ||
|
|
||
|
|
||
| if ($event instanceof ElementEvent) { | ||
|
|
||
| // Prevent purge on updates of drafts or revisions | ||
|
|
@@ -223,16 +228,11 @@ protected static function handleUpdateEvent(Event $event) | |
| return; | ||
| } | ||
|
|
||
| // For nested elements (blocks), purge the root owner's tags | ||
| // 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))) { | ||
|
Comment on lines
+231
to
+235
|
||
| if ($event->element instanceof \craft\elements\GlobalSet && is_string($event->element->handle)) { | ||
| $tags[] = $event->element->handle; | ||
| } elseif ($event->element instanceof \craft\elements\Asset && $event->isNew) { | ||
|
|
||
There was a problem hiding this comment.
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).