From c82c9b71fde28ddc33ed07a0748269c5b383e78b Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Tue, 9 May 2023 15:38:43 +0200 Subject: [PATCH 1/9] Added additional tag cleaning to limit down number of orphaned tag entries --- .../Core/Persistence/Cache/ContentHandler.php | 36 ++++++++++++++++--- .../Core/Persistence/Cache/TrashHandler.php | 22 +++++++++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php index 4a6fa023f4..f062195554 100644 --- a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php @@ -328,12 +328,34 @@ public function updateContent($contentId, $versionNo, UpdateStruct $struct) { $this->logger->logCall(__METHOD__, ['content' => $contentId, 'version' => $versionNo, 'struct' => $struct]); $content = $this->persistenceHandler->contentHandler()->updateContent($contentId, $versionNo, $struct); - $this->cache->invalidateTags([ - $this->cacheIdentifierGenerator->generateTag( + $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); + + + $locationTags = array_map(function (Content\Location $location) { + return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$location->id]); + }, $locations); + $locationPathTags = array_map(function (Content\Location $location) { + return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$location->id]); + }, $locations); + + $versionTags = []; + $versionTags[] = $this->cacheIdentifierGenerator->generateTag( + self::CONTENT_VERSION_IDENTIFIER, + [$contentId, $versionNo] + ); + if ($versionNo > 1) { + $versionTags[] = $this->cacheIdentifierGenerator->generateTag( self::CONTENT_VERSION_IDENTIFIER, - [$contentId, $versionNo] - ), - ]); + [$contentId, $versionNo - 1] + ); + } + + $tags = array_merge( + $locationTags, + $locationPathTags, + $versionTags + ); + $this->cache->invalidateTags($tags); return $content; } @@ -350,6 +372,7 @@ public function deleteContent($contentId) $contentId, APIRelation::FIELD | APIRelation::ASSET ); + $contentLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); $return = $this->persistenceHandler->contentHandler()->deleteContent($contentId); @@ -365,6 +388,9 @@ function ($relation) { $tags = []; } $tags[] = $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$contentId]); + foreach ($contentLocations as $location) { + $tags[] = $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$location->id]); + } $this->cache->invalidateTags($tags); return $return; diff --git a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php index 78e9e0eb0c..e28d0a6361 100644 --- a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php @@ -9,6 +9,7 @@ use eZ\Publish\API\Repository\Values\Content\Query\Criterion; use eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler as TrashHandlerInterface; use eZ\Publish\SPI\Persistence\Content\Relation; +use eZ\Publish\SPI\Persistence\Content\VersionInfo; /** * @see \eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler @@ -17,6 +18,8 @@ class TrashHandler extends AbstractHandler implements TrashHandlerInterface { private const EMPTY_TRASH_BULK_SIZE = 100; private const CONTENT_IDENTIFIER = 'content'; + private const CONTENT_VERSION_IDENTIFIER = 'content_version'; + private const LOCATION_IDENTIFIER = 'location'; private const LOCATION_PATH_IDENTIFIER = 'location_path'; /** @@ -37,8 +40,9 @@ public function trashSubtree($locationId) $this->logger->logCall(__METHOD__, ['locationId' => $locationId]); $location = $this->persistenceHandler->locationHandler()->load($locationId); - $reverseRelations = $this->persistenceHandler->contentHandler()->loadRelations($location->contentId); - + $contentId = $location->contentId; + $reverseRelations = $this->persistenceHandler->contentHandler()->loadRelations($contentId); + $versions = $this->persistenceHandler->contentHandler()->listVersions($contentId); $return = $this->persistenceHandler->trashHandler()->trashSubtree($locationId); $relationTags = []; @@ -51,12 +55,21 @@ public function trashSubtree($locationId) }, $reverseRelations); } + $versionTags = array_map(function (VersionInfo $versionInfo) use ($contentId) { + return $this->cacheIdentifierGenerator->generateTag( + self::CONTENT_VERSION_IDENTIFIER, + [$contentId, $versionInfo->versionNo] + ); + }, $versions); + $tags = array_merge( [ - $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$location->contentId]), + $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$contentId]), $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$locationId]), + $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$locationId]), ], - $relationTags + $relationTags, + $versionTags ); $this->cache->invalidateTags(array_values(array_unique($tags))); @@ -126,6 +139,7 @@ public function emptyTrash() $tags[$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$trashedItem->contentId])] = true; $tags[$this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$trashedItem->id])] = true; + } $offset += self::EMPTY_TRASH_BULK_SIZE; // Once offset is larger than total count we can exit From 4b7e56ce183eeb4b81af1940dbc52a2fd55cacb8 Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Tue, 9 May 2023 16:30:49 +0200 Subject: [PATCH 2/9] CS fixed --- eZ/Publish/Core/Persistence/Cache/ContentHandler.php | 1 - eZ/Publish/Core/Persistence/Cache/TrashHandler.php | 1 - 2 files changed, 2 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php index f062195554..2b5154efad 100644 --- a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php @@ -330,7 +330,6 @@ public function updateContent($contentId, $versionNo, UpdateStruct $struct) $content = $this->persistenceHandler->contentHandler()->updateContent($contentId, $versionNo, $struct); $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); - $locationTags = array_map(function (Content\Location $location) { return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$location->id]); }, $locations); diff --git a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php index e28d0a6361..cc1baeed63 100644 --- a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php @@ -139,7 +139,6 @@ public function emptyTrash() $tags[$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$trashedItem->contentId])] = true; $tags[$this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$trashedItem->id])] = true; - } $offset += self::EMPTY_TRASH_BULK_SIZE; // Once offset is larger than total count we can exit From fc201777b0abcb858323d007046869312af4251d Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Thu, 10 Aug 2023 13:44:37 +0200 Subject: [PATCH 3/9] Fixed test + changes after CR --- .../Cache/Tests/ContentHandlerTest.php | 122 +++++++++++++++--- .../Cache/Tests/TrashHandlerTest.php | 22 +++- .../Core/Persistence/Cache/TrashHandler.php | 2 +- 3 files changed, 122 insertions(+), 24 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php index 42b3f95535..4c0deae62e 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php @@ -12,11 +12,13 @@ use eZ\Publish\SPI\Persistence\Content\ContentInfo; use eZ\Publish\SPI\Persistence\Content\CreateStruct; use eZ\Publish\SPI\Persistence\Content\Handler as SPIContentHandler; +use eZ\Publish\SPI\Persistence\Content\Location\Handler as SPILocationHandler; use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct; use eZ\Publish\SPI\Persistence\Content\Relation as SPIRelation; use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct; use eZ\Publish\SPI\Persistence\Content\UpdateStruct; use eZ\Publish\SPI\Persistence\Content\VersionInfo; +use PHPUnit\Framework\MockObject\MockObject; /** * Test case for Persistence\Cache\ContentHandler. @@ -47,7 +49,7 @@ public function providerForUnCachedMethods(): array ['setStatus', [2, 0, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']], ['setStatus', [2, 1, 1], [['content', [2], false]], null, ['c-2']], ['updateMetadata', [2, new MetadataUpdateStruct()], [['content', [2], false]], null, ['c-2']], - ['updateContent', [2, 1, new UpdateStruct()], [['content_version', [2, 1], false]], null, ['c-2-v-1']], + //['updateContent', [2, 1, new UpdateStruct()], [['content_version', [2, 1], false]], null, ['c-2-v-1']], //['deleteContent', [2]], own tests for relations complexity ['deleteVersion', [2, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']], ['addRelation', [new RelationCreateStruct()]], @@ -303,6 +305,51 @@ public function providerForCachedLoadMethodsMiss(): array ]; } + /** + * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateContent + */ + public function testUpdateContent() + { + $this->loggerMock->expects($this->once())->method('logCall'); + + $innerContentHandlerMock = $this->createMock(SPIContentHandler::class); + $innerLocationHandlerMock = $this->createMock(SPILocationHandler::class); + + $this->prepareHandlerMocks( + $innerContentHandlerMock, + $innerLocationHandlerMock, + 1, + 1, + 0 + ); + + $innerContentHandlerMock + ->expects($this->once()) + ->method('updateContent') + ->with(2, 1, new UpdateStruct()) + ->willReturn(new Content()); + + $this->cacheIdentifierGeneratorMock + ->expects($this->exactly(5)) + ->method('generateTag') + ->withConsecutive( + ['location', [3], false], + ['location', [4], false], + ['location_path', [3], false], + ['location_path', [4], false], + ['content_version', [2, 1], false], + ) + ->willReturnOnConsecutiveCalls('l-3', 'l-4', 'lp-3', 'lp-4', 'c-2-v-1'); + + $this->cacheMock + ->expects($this->once()) + ->method('invalidateTags') + ->with(['l-3', 'l-4', 'lp-3', 'lp-4', 'c-2-v-1']); + + $handler = $this->persistenceCacheHandler->contentHandler(); + $handler->updateContent(2, 1, new UpdateStruct()); + } + /** * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent */ @@ -310,23 +357,16 @@ public function testDeleteContent() { $this->loggerMock->expects($this->once())->method('logCall'); - $innerHandlerMock = $this->createMock(SPIContentHandler::class); - $this->persistenceHandlerMock - ->expects($this->exactly(2)) - ->method('contentHandler') - ->willReturn($innerHandlerMock); + $innerContentHandlerMock = $this->createMock(SPIContentHandler::class); + $innerLocationHandlerMock = $this->createMock(SPILocationHandler::class); - $innerHandlerMock - ->expects($this->once()) - ->method('loadReverseRelations') - ->with(2, APIRelation::FIELD | APIRelation::ASSET) - ->willReturn( - [ - new SPIRelation(['sourceContentId' => 42]), - ] - ); + $this->prepareHandlerMocks( + $innerContentHandlerMock, + $innerLocationHandlerMock, + 2 + ); - $innerHandlerMock + $innerContentHandlerMock ->expects($this->once()) ->method('deleteContent') ->with(2) @@ -337,20 +377,62 @@ public function testDeleteContent() ->method('deleteItem'); $this->cacheIdentifierGeneratorMock - ->expects($this->exactly(2)) + ->expects($this->exactly(4)) ->method('generateTag') ->withConsecutive( ['content', [42], false], - ['content', [2], false] + ['content', [2], false], + ['location', [3], false], + ['location', [4], false] ) - ->willReturnOnConsecutiveCalls('c-42', 'c-2'); + ->willReturnOnConsecutiveCalls('c-42', 'c-2', 'l-3', 'l-4'); $this->cacheMock ->expects($this->once()) ->method('invalidateTags') - ->with(['c-42', 'c-2']); + ->with(['c-42', 'c-2', 'l-3', 'l-4']); $handler = $this->persistenceCacheHandler->contentHandler(); $handler->deleteContent(2); } + + private function prepareHandlerMocks( + MockObject $innerContentHandlerMock, + MockObject $innerLocationHandlerMock, + int $contentHandlerCount = 1, + int $locationHandlerCount = 1, + int $loadReverseRelationsCount = 1, + int $loadLocationsByContentCount = 1 + ): void { + $this->persistenceHandlerMock + ->expects($this->exactly($contentHandlerCount)) + ->method('contentHandler') + ->willReturn($innerContentHandlerMock); + + $innerContentHandlerMock + ->expects($this->exactly($loadReverseRelationsCount)) + ->method('loadReverseRelations') + ->with(2, APIRelation::FIELD | APIRelation::ASSET) + ->willReturn( + [ + new SPIRelation(['sourceContentId' => 42]), + ] + ); + + $this->persistenceHandlerMock + ->expects($this->exactly($locationHandlerCount)) + ->method('locationHandler') + ->willReturn($innerLocationHandlerMock); + + $innerLocationHandlerMock + ->expects($this->exactly($loadLocationsByContentCount)) + ->method('loadLocationsByContent') + ->with(2) + ->willReturn( + [ + new Content\Location(['id' => 3]), + new Content\Location(['id' => 4]), + ] + ); + } } diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php index 6dea7fc036..0040f9ee4b 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php @@ -13,6 +13,7 @@ use eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler as TrashHandler; use eZ\Publish\SPI\Persistence\Content\Location\Trashed; use eZ\Publish\SPI\Persistence\Content\Relation; +use eZ\Publish\SPI\Persistence\Content\VersionInfo; /** * Test case for Persistence\Cache\SectionHandler. @@ -118,10 +119,13 @@ public function testTrashSubtree() { $locationId = 6; $contentId = 42; + $versionNo = 1; $tags = [ - 'c-' . $contentId, 'lp-' . $locationId, + 'l-' . $locationId, + 'c-' . $contentId . '-v-' . $versionNo, + 'c-' . $contentId, ]; $handlerMethodName = $this->getHandlerMethodName(); @@ -144,6 +148,16 @@ public function testTrashSubtree() ->method('locationHandler') ->willReturn($locationHandlerMock); + $contentHandlerMock + ->expects($this->once()) + ->method('listVersions') + ->with($contentId) + ->willReturn( + [ + new VersionInfo(['versionNo' => $versionNo]), + ] + ); + $this->persistenceHandlerMock ->expects($this->once()) ->method($handlerMethodName) @@ -156,11 +170,13 @@ public function testTrashSubtree() ->willReturn(null); $this->cacheIdentifierGeneratorMock - ->expects($this->exactly(2)) + ->expects($this->exactly(4)) ->method('generateTag') ->withConsecutive( + ['content_version', [$contentId, $versionNo], false], ['content', [$contentId], false], - ['location_path', [$locationId], false] + ['location_path', [$locationId], false], + ['location', [$locationId], false] ) ->willReturnOnConsecutiveCalls(...$tags); diff --git a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php index cc1baeed63..44377372b8 100644 --- a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php @@ -55,7 +55,7 @@ public function trashSubtree($locationId) }, $reverseRelations); } - $versionTags = array_map(function (VersionInfo $versionInfo) use ($contentId) { + $versionTags = array_map(function (VersionInfo $versionInfo) use ($contentId): string { return $this->cacheIdentifierGenerator->generateTag( self::CONTENT_VERSION_IDENTIFIER, [$contentId, $versionInfo->versionNo] From 0bc8d926ea776f2249f5bb67d7e3bc2bbe2a866f Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Thu, 10 Aug 2023 14:16:02 +0200 Subject: [PATCH 4/9] Fixed the last test --- eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php | 5 ++--- eZ/Publish/Core/Persistence/Cache/TrashHandler.php | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php index 0040f9ee4b..6fd51e27fc 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/TrashHandlerTest.php @@ -122,10 +122,10 @@ public function testTrashSubtree() $versionNo = 1; $tags = [ - 'lp-' . $locationId, - 'l-' . $locationId, 'c-' . $contentId . '-v-' . $versionNo, 'c-' . $contentId, + 'lp-' . $locationId, + 'l-' . $locationId, ]; $handlerMethodName = $this->getHandlerMethodName(); @@ -168,7 +168,6 @@ public function testTrashSubtree() ->method('trashSubtree') ->with($locationId) ->willReturn(null); - $this->cacheIdentifierGeneratorMock ->expects($this->exactly(4)) ->method('generateTag') diff --git a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php index 44377372b8..a5e03abf2b 100644 --- a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php @@ -63,14 +63,15 @@ public function trashSubtree($locationId) }, $versions); $tags = array_merge( + $versionTags, + $relationTags, [ $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$contentId]), $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$locationId]), $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$locationId]), ], - $relationTags, - $versionTags ); + $this->cache->invalidateTags(array_values(array_unique($tags))); return $return; From 82d6a7d6662e57ddbee25e45b63538d43f449ee1 Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Thu, 4 Jan 2024 11:18:26 +0100 Subject: [PATCH 5/9] Update eZ/Publish/Core/Persistence/Cache/ContentHandler.php Co-authored-by: Konrad Oboza --- eZ/Publish/Core/Persistence/Cache/ContentHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php index 2b5154efad..ba41342b57 100644 --- a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php @@ -330,7 +330,7 @@ public function updateContent($contentId, $versionNo, UpdateStruct $struct) $content = $this->persistenceHandler->contentHandler()->updateContent($contentId, $versionNo, $struct); $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); - $locationTags = array_map(function (Content\Location $location) { + $locationTags = array_map(function (Content\Location $location): string { return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$location->id]); }, $locations); $locationPathTags = array_map(function (Content\Location $location) { From 9aa11310246c182cf6f32dc35261ca036fe69926 Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Thu, 4 Jan 2024 11:18:32 +0100 Subject: [PATCH 6/9] Update eZ/Publish/Core/Persistence/Cache/ContentHandler.php Co-authored-by: Konrad Oboza --- eZ/Publish/Core/Persistence/Cache/ContentHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php index ba41342b57..6e9a3fd339 100644 --- a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php @@ -333,7 +333,7 @@ public function updateContent($contentId, $versionNo, UpdateStruct $struct) $locationTags = array_map(function (Content\Location $location): string { return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$location->id]); }, $locations); - $locationPathTags = array_map(function (Content\Location $location) { + $locationPathTags = array_map(function (Content\Location $location): string { return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$location->id]); }, $locations); From e04b7fbfae8b945a879b96479aae5720d67b2b80 Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Mon, 25 Nov 2024 12:47:02 +0100 Subject: [PATCH 7/9] Applying CR suggestions --- .../Cache/Tests/ContentHandlerTest.php | 21 ++++++++++--------- .../Core/Persistence/Cache/TrashHandler.php | 7 ++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php index 4c0deae62e..2bfa20bd32 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php @@ -49,7 +49,7 @@ public function providerForUnCachedMethods(): array ['setStatus', [2, 0, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']], ['setStatus', [2, 1, 1], [['content', [2], false]], null, ['c-2']], ['updateMetadata', [2, new MetadataUpdateStruct()], [['content', [2], false]], null, ['c-2']], - //['updateContent', [2, 1, new UpdateStruct()], [['content_version', [2, 1], false]], null, ['c-2-v-1']], + ['updateContent', [2, 1, new UpdateStruct()], [['content_version', [2, 1], false]], null, ['c-2-v-1']], //['deleteContent', [2]], own tests for relations complexity ['deleteVersion', [2, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']], ['addRelation', [new RelationCreateStruct()]], @@ -308,7 +308,7 @@ public function providerForCachedLoadMethodsMiss(): array /** * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateContent */ - public function testUpdateContent() + public function testUpdateContent(): void { $this->loggerMock->expects($this->once())->method('logCall'); @@ -332,14 +332,15 @@ public function testUpdateContent() $this->cacheIdentifierGeneratorMock ->expects($this->exactly(5)) ->method('generateTag') - ->withConsecutive( - ['location', [3], false], - ['location', [4], false], - ['location_path', [3], false], - ['location_path', [4], false], - ['content_version', [2, 1], false], - ) - ->willReturnOnConsecutiveCalls('l-3', 'l-4', 'lp-3', 'lp-4', 'c-2-v-1'); + ->will( + self::returnValueMap([ + ['location', [3], false, 'l-3'], + ['location', [4], false, 'l-4'], + ['location_path', [3], false, 'lp-3'], + ['location_path', [4], false, 'lp-4'], + ['content_version', [2, 1], false, 'c-2-v-1'], + ]) + ); $this->cacheMock ->expects($this->once()) diff --git a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php index a5e03abf2b..bbb8ece068 100644 --- a/eZ/Publish/Core/Persistence/Cache/TrashHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/TrashHandler.php @@ -41,8 +41,9 @@ public function trashSubtree($locationId) $location = $this->persistenceHandler->locationHandler()->load($locationId); $contentId = $location->contentId; - $reverseRelations = $this->persistenceHandler->contentHandler()->loadRelations($contentId); - $versions = $this->persistenceHandler->contentHandler()->listVersions($contentId); + $contentHandler = $this->persistenceHandler->contentHandler(); + $reverseRelations = $contentHandler->loadRelations($contentId); + $versions = $contentHandler->listVersions($contentId); $return = $this->persistenceHandler->trashHandler()->trashSubtree($locationId); $relationTags = []; @@ -56,7 +57,7 @@ public function trashSubtree($locationId) } $versionTags = array_map(function (VersionInfo $versionInfo) use ($contentId): string { - return $this->cacheIdentifierGenerator->generateTag( + return $this->cacheIdentifierGenerator->generateTag( self::CONTENT_VERSION_IDENTIFIER, [$contentId, $versionInfo->versionNo] ); From 007f204e67b6a2dd0883bd3ec155ec57ac664c06 Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Tue, 10 Dec 2024 15:12:57 +0100 Subject: [PATCH 8/9] Commented out bulk test for as now it have it own specific test --- eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php index 2bfa20bd32..7cb0e32d20 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php @@ -49,7 +49,8 @@ public function providerForUnCachedMethods(): array ['setStatus', [2, 0, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']], ['setStatus', [2, 1, 1], [['content', [2], false]], null, ['c-2']], ['updateMetadata', [2, new MetadataUpdateStruct()], [['content', [2], false]], null, ['c-2']], - ['updateContent', [2, 1, new UpdateStruct()], [['content_version', [2, 1], false]], null, ['c-2-v-1']], + //updateContent has it own test now due relations complexity + //['updateContent', [2, 1, new UpdateStruct()], [['content_version', [2, 1], false]], null, ['c-2-v-1']], //['deleteContent', [2]], own tests for relations complexity ['deleteVersion', [2, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']], ['addRelation', [new RelationCreateStruct()]], From e96294df532ba333eed907aaa87b508e62d5402e Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Tue, 10 Dec 2024 15:13:44 +0100 Subject: [PATCH 9/9] Fixed grammar mistakes in the comment --- eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php index 7cb0e32d20..833c82266e 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php @@ -49,7 +49,7 @@ public function providerForUnCachedMethods(): array ['setStatus', [2, 0, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']], ['setStatus', [2, 1, 1], [['content', [2], false]], null, ['c-2']], ['updateMetadata', [2, new MetadataUpdateStruct()], [['content', [2], false]], null, ['c-2']], - //updateContent has it own test now due relations complexity + //updateContent has its own test now due to relations complexity //['updateContent', [2, 1, new UpdateStruct()], [['content_version', [2, 1], false]], null, ['c-2-v-1']], //['deleteContent', [2]], own tests for relations complexity ['deleteVersion', [2, 1], [['content_version', [2, 1], false]], null, ['c-2-v-1']],