Skip to content

Commit aace323

Browse files
committed
Don't cache GraphQL results if they contain transform generation URLs
Fixes #18581
1 parent 9a05d24 commit aace323

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Craft CMS 4
22

3+
## Unreleased
4+
5+
- Fixed a bug where GraphQL results were getting cached even if they contained transform generation URLs. ([#18581](https://github.com/craftcms/cms/issues/18581))
6+
37
## 4.17.11 - 2026-03-17
48

59
- Fixed an error that could occur after running the `utils/fix-field-layout-uids` command. ([#18516](https://github.com/craftcms/cms/issues/18516))

src/services/Gql.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public function executeQuery(
534534

535535
[$dep, $duration] = $elementsService->stopCollectingCacheInfo();
536536

537-
if (empty($event->result['errors']) && $cacheKey) {
537+
if (empty($event->result['errors']) && $cacheKey && $this->shouldCache($event->result ?? [])) {
538538
$this->setCachedResult($cacheKey, $event->result, $dep, $duration);
539539
}
540540
}
@@ -545,6 +545,23 @@ public function executeQuery(
545545
return $event->result ?? [];
546546
}
547547

548+
private function shouldCache(array $result): bool
549+
{
550+
foreach ($result as $value) {
551+
if (is_string($value)) {
552+
if (str_contains(stripslashes($value), 'assets/generate-transform')) {
553+
return false;
554+
}
555+
} elseif (is_array($value)) {
556+
if (!$this->shouldCache($value)) {
557+
return false;
558+
}
559+
}
560+
}
561+
562+
return true;
563+
}
564+
548565
/**
549566
* Invalidates all GraphQL result caches.
550567
*

0 commit comments

Comments
 (0)