From 2fbf8ca9ad32165d30662ec52623469dc47b6c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Tue, 22 Oct 2024 11:42:08 +0200 Subject: [PATCH] IBX-9103: Fixed cache tag name not including relation type (#437) For more details see https://issues.ibexa.co/browse/IBX-9103 and https://github.com/ibexa/core/pull/437 Key changes: * IBX-9103: Fixed cache tag name not including relation type --- src/lib/Persistence/Cache/ContentHandler.php | 6 ++--- .../settings/storage_engines/cache.yml | 2 +- .../Persistence/Cache/ContentHandlerTest.php | 23 +++++++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lib/Persistence/Cache/ContentHandler.php b/src/lib/Persistence/Cache/ContentHandler.php index 9047a4c182..a54e6bb293 100644 --- a/src/lib/Persistence/Cache/ContentHandler.php +++ b/src/lib/Persistence/Cache/ContentHandler.php @@ -620,18 +620,18 @@ public function countReverseRelations(int $destinationContentId, ?int $type = nu $cacheItem = $this->cache->getItem( $this->cacheIdentifierGenerator->generateKey( self::CONTENT_REVERSE_RELATIONS_COUNT_IDENTIFIER, - [$destinationContentId], + [$destinationContentId, $type], true ) ); if ($cacheItem->isHit()) { - $this->logger->logCacheHit(['content' => $destinationContentId]); + $this->logger->logCacheHit(['content' => $destinationContentId, 'type' => $type]); return $cacheItem->get(); } - $this->logger->logCacheMiss(['content' => $destinationContentId]); + $this->logger->logCacheMiss(['content' => $destinationContentId, 'type' => $type]); $reverseRelationsCount = $this->persistenceHandler->contentHandler()->countReverseRelations($destinationContentId, $type); $cacheItem->set($reverseRelationsCount); $tags = [ diff --git a/src/lib/Resources/settings/storage_engines/cache.yml b/src/lib/Resources/settings/storage_engines/cache.yml index 48bb148387..aa1a21fec8 100644 --- a/src/lib/Resources/settings/storage_engines/cache.yml +++ b/src/lib/Resources/settings/storage_engines/cache.yml @@ -121,7 +121,7 @@ parameters: content_locations: 'cl-%s' content_relations_count_with_by_version_type_suffix: 'crc-%%s-v-%%s-t-%%s' content_relations_list_with_by_version_type_suffix: 'crl-%%s-l-%%s-o-%%s-v-%%s-t-%%s' - content_reverse_relations_count: 'crrc-%s' + content_reverse_relations_count: 'crrc-%%s-t-%%s' content_version_info: 'cvi-%s' content_version_list: 'c-%s-vl' content_version: 'c-%%s-v-%%s' diff --git a/tests/lib/Persistence/Cache/ContentHandlerTest.php b/tests/lib/Persistence/Cache/ContentHandlerTest.php index c7c43308fa..38ccfcae05 100644 --- a/tests/lib/Persistence/Cache/ContentHandlerTest.php +++ b/tests/lib/Persistence/Cache/ContentHandlerTest.php @@ -93,7 +93,8 @@ public function providerForCachedLoadMethodsHit(): array // string $method, array $arguments, string $key, array? $tagGeneratingArguments, array? $tagGeneratingResults, array? $keyGeneratingArguments, array? $keyGeneratingResults, mixed? $data, bool $multi = false, array $additionalCalls return [ - ['countReverseRelations', [2], 'ibx-crrc-2', null, null, [['content_reverse_relations_count', [2], true]], ['ibx-crrc-2'], 10], + ['countReverseRelations', [2, null], 'ibx-crrc-2-t-', null, null, [['content_reverse_relations_count', [2, null], true]], ['ibx-crrc-2-t-'], 10], + ['countReverseRelations', [2, 8], 'ibx-crrc-2-t-8', null, null, [['content_reverse_relations_count', [2, 8], true]], ['ibx-crrc-2-t-8'], 10], ['countRelations', [2], 'ibx-crc-2-v--t-', null, null, [['content_relations_count_with_by_version_type_suffix', [2, null, null], true]], ['ibx-crc-2-v--t-'], 10], ['countRelations', [2, 2], 'ibx-crc-2-v-2-t-', null, null, [['content_relations_count_with_by_version_type_suffix', [2, 2, null], true]], ['ibx-crc-2-v-2-t-'], 10], ['countRelations', [2, null, 1], 'ibx-crc-2-v--t-1', null, null, [['content_relations_count_with_by_version_type_suffix', [2, null, 1], true]], ['ibx-crc-2-v--t-1'], 10], @@ -136,15 +137,29 @@ public function providerForCachedLoadMethodsMiss(): array [ 'countReverseRelations', [2], - 'ibx-crrc-2', + 'ibx-crrc-2-t-', [ ['content', [2], false], ], ['c-2'], [ - ['content_reverse_relations_count', [2], true], + ['content_reverse_relations_count', [2, null], true], ], - ['ibx-crrc-2'], + ['ibx-crrc-2-t-'], + 10, + ], + [ + 'countReverseRelations', + [2, 8], + 'ibx-crrc-2-t-8', + [ + ['content', [2], false], + ], + ['c-2'], + [ + ['content_reverse_relations_count', [2, 8], true], + ], + ['ibx-crrc-2-t-8'], 10, ], [