From 65efb05563ad269ac4dee203948d2bba3676710b Mon Sep 17 00:00:00 2001 From: bencroker Date: Mon, 12 Feb 2024 17:38:26 -0600 Subject: [PATCH] Fix tracking of eager-loaded block elements --- CHANGELOG.md | 6 ++++ composer.json | 2 +- src/Blitz.php | 2 +- ..._clear_out_legacy_cached_element_types.php | 29 +++++++++++++++++++ src/services/GenerateCacheService.php | 9 ++++-- 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 src/migrations/m240212_120000_clear_out_legacy_cached_element_types.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c456dbbf..3b928306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Blitz +## 4.11.1 - 2024-02-12 + +### Fixed + +- Fixed the tracking of non-cacheable block elements when eager-loaded. + ## 4.11.0 - 2024-02-12 ### Added diff --git a/composer.json b/composer.json index c23bad82..ff4ecdc9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "putyourlightson/craft-blitz", "description": "Intelligent static page caching for creating lightning-fast sites.", - "version": "4.11.0", + "version": "4.11.1", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/blitz", "license": "proprietary", diff --git a/src/Blitz.php b/src/Blitz.php index 4150e1f7..719deb47 100644 --- a/src/Blitz.php +++ b/src/Blitz.php @@ -109,7 +109,7 @@ public static function config(): array /** * @inheritdoc */ - public string $schemaVersion = '4.10.1'; + public string $schemaVersion = '4.11.1'; /** * @inheritdoc diff --git a/src/migrations/m240212_120000_clear_out_legacy_cached_element_types.php b/src/migrations/m240212_120000_clear_out_legacy_cached_element_types.php new file mode 100644 index 00000000..203ba55d --- /dev/null +++ b/src/migrations/m240212_120000_clear_out_legacy_cached_element_types.php @@ -0,0 +1,29 @@ +safeUp(); + + return true; + } + + /** + * @inheritdoc + */ + public function safeDown(): bool + { + echo self::class . " cannot be reverted.\n"; + + return true; + } +} diff --git a/src/services/GenerateCacheService.php b/src/services/GenerateCacheService.php index 62cfc034..9a3adbe5 100755 --- a/src/services/GenerateCacheService.php +++ b/src/services/GenerateCacheService.php @@ -152,9 +152,12 @@ function(EagerLoadElementsEvent $event) { /** @var ElementInterface|string $elementType */ $elementType = $event->elementType; $map = $elementType::eagerLoadingMap($event->elements, $plan->handle); - if (!empty($map['map'])) { - foreach ($map['map'] as $mapping) { - $this->generateData->addElementId($mapping['target']); + + if (is_array($map)) { + if ($this->_shouldTrackElementsOfType($map['elementType'])) { + foreach ($map['map'] as $mapping) { + $this->generateData->addElementId($mapping['target']); + } } } }