From 702658ee662bd6f116643d46333efca00057659a Mon Sep 17 00:00:00 2001 From: bencroker Date: Wed, 13 Nov 2024 10:13:47 +0100 Subject: [PATCH] Fix cache generation bug --- CHANGELOG.md | 10 +++++++++- composer.json | 2 +- src/services/CacheRequestService.php | 13 +++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7b77920..12345410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,15 @@ # Release Notes for Blitz +## 5.9.4 - 2024-11-13 + +### Fixed + +- Fixed a bug introduced in version 5.9.3 that broke cache generation when “Do not cache URLs with query strings” was selected ([#733](https://github.com/putyourlightson/craft-blitz/issues/733)). + ## 5.9.3 - 2024-11-07 +### Fixed + - Fixed a bug in which pages with query strings in their URLs could be cached even when “Do not cache URLs with query strings” was selected ([#729](https://github.com/putyourlightson/craft-blitz/issues/729)). ## 5.9.2 - 2024-11-04 @@ -9,7 +17,7 @@ ### Fixed - Fixed an error that could occur when generating tagged caches in some cases ([#728](https://github.com/putyourlightson/craft-blitz/issues/728)). -- Fixed a bug in which refresh jobs we re not being created immediately in some console commands. +- Fixed a bug in which refresh jobs were not being created immediately in some console commands. ## 5.9.1 - 2024-10-22 diff --git a/composer.json b/composer.json index dec80f55..0bcd9012 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": "5.9.3", + "version": "5.9.4", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/blitz", "license": "proprietary", diff --git a/src/services/CacheRequestService.php b/src/services/CacheRequestService.php index 81159b12..e96a3c9c 100755 --- a/src/services/CacheRequestService.php +++ b/src/services/CacheRequestService.php @@ -251,7 +251,7 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool } if (Blitz::$plugin->settings->queryStringCaching == SettingsModel::QUERY_STRINGS_DO_NOT_CACHE_URLS) { - $queryStringParams = $this->getQueryStringParams($siteUri->uri); + $queryStringParams = $this->getQueryStringParamsWithoutToken($siteUri->uri); if (!empty($queryStringParams)) { Blitz::$plugin->debug('Page not cached because a query string was provided with the query string caching setting disabled.', [], $url); @@ -557,13 +557,18 @@ public function matchesQueryStringParams(int $siteId, string $param, array|strin } /** - * Returns the query string params of the URI. + * Returns the query string params of the URI without the token param. */ - public function getQueryStringParams(string $uri): array + public function getQueryStringParamsWithoutToken(string $uri): array { $queryString = parse_url($uri, PHP_URL_QUERY) ?: ''; parse_str($queryString, $queryStringParams); + $tokenParam = Craft::$app->getConfig()->getGeneral()->tokenParam; + if (isset($queryStringParams[$tokenParam])) { + unset($queryStringParams[$tokenParam]); + } + return $queryStringParams; } @@ -576,7 +581,7 @@ public function getAllowedQueryString(int $siteId, string $uri): string return $this->allowedQueryStrings[$siteId][$uri]; } - $queryStringParams = $this->getQueryStringParams($uri); + $queryStringParams = $this->getQueryStringParamsWithoutToken($uri); if (!$this->getIsCachedInclude($uri)) { foreach ($queryStringParams as $key => $value) {