-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-5502: Added additional tag cleaning to limit down number of orphaned tag en… #477
base: 4.6
Are you sure you want to change the base?
Changes from all commits
3f3b12e
b8b1d0f
3ab8eab
7055240
d7fe485
ed32613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -335,12 +335,33 @@ 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); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you checked the impact of this on performance? Every load inside caching system is a potential risk. I'd like to avoid the situation where we release some memory, but make longer update time as the cost. |
||||||||||||||||||||||
$locationTags = array_map(function (Content\Location $location): string { | ||||||||||||||||||||||
return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$location->id]); | ||||||||||||||||||||||
}, $locations); | ||||||||||||||||||||||
Comment on lines
+339
to
+341
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not very readable to me. How about:
Suggested change
|
||||||||||||||||||||||
$locationPathTags = array_map(function (Content\Location $location): string { | ||||||||||||||||||||||
return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$location->id]); | ||||||||||||||||||||||
}, $locations); | ||||||||||||||||||||||
Comment on lines
+342
to
+344
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given |
||||||||||||||||||||||
|
||||||||||||||||||||||
$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] | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not invalidate tags for an unrelated versions. The cache performance side effects of that might be difficult to predict. |
||||||||||||||||||||||
); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
$tags = array_merge( | ||||||||||||||||||||||
$locationTags, | ||||||||||||||||||||||
$locationPathTags, | ||||||||||||||||||||||
$versionTags | ||||||||||||||||||||||
); | ||||||||||||||||||||||
$this->cache->invalidateTags($tags); | ||||||||||||||||||||||
Comment on lines
+359
to
+364
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of all the above comments, maybe...
Suggested change
instead of performing very similar loads to what that callable does? |
||||||||||||||||||||||
|
||||||||||||||||||||||
return $content; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
@@ -357,6 +378,7 @@ public function deleteContent($contentId) | |||||||||||||||||||||
$contentId, | ||||||||||||||||||||||
APIRelation::FIELD | APIRelation::ASSET | ||||||||||||||||||||||
); | ||||||||||||||||||||||
$contentLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); | ||||||||||||||||||||||
|
||||||||||||||||||||||
$return = $this->persistenceHandler->contentHandler()->deleteContent($contentId); | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -372,6 +394,10 @@ 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; | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,15 @@ | |
|
||
use Ibexa\Contracts\Core\Persistence\Content\Location\Trash\Handler as TrashHandlerInterface; | ||
use Ibexa\Contracts\Core\Persistence\Content\Relation; | ||
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
|
||
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'; | ||
Comment on lines
17
to
20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh, let's fix it while at it, because adding new consts like that contradicts the purpose of those consts. What you need to do is make b) is preferred, but maybe a bit out of scope for you. a) is easily achievable. The point of using a const there is usage search. When I'm searching for |
||
|
||
/** | ||
|
@@ -34,8 +37,11 @@ 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; | ||
|
||
$contentHandler = $this->persistenceHandler->contentHandler(); | ||
$reverseRelations = $contentHandler->loadRelations($contentId); | ||
$versions = $contentHandler->listVersions($contentId); | ||
$return = $this->persistenceHandler->trashHandler()->trashSubtree($locationId); | ||
|
||
$relationTags = []; | ||
|
@@ -48,12 +54,21 @@ public function trashSubtree($locationId) | |
}, $reverseRelations); | ||
} | ||
|
||
$versionTags = array_map(function (VersionInfo $versionInfo) use ($contentId): string { | ||
return $this->cacheIdentifierGenerator->generateTag( | ||
self::CONTENT_VERSION_IDENTIFIER, | ||
[$contentId, $versionInfo->versionNo] | ||
); | ||
}, $versions); | ||
|
||
$tags = array_merge( | ||
$versionTags, | ||
$relationTags, | ||
[ | ||
$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$location->contentId]), | ||
$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$contentId]), | ||
$this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$locationId]), | ||
], | ||
$relationTags | ||
$this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$locationId]), | ||
] | ||
); | ||
$this->cache->invalidateTags(array_values(array_unique($tags))); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
use Ibexa\Contracts\Core\Persistence\Content\ContentInfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||
use Ibexa\Contracts\Core\Persistence\Content\CreateStruct; | ||||||||||||||||||||||||||||||||||||||||||||||||||
use Ibexa\Contracts\Core\Persistence\Content\Handler as SPIContentHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as SPILocationHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technical debt: |
||||||||||||||||||||||||||||||||||||||||||||||||||
use Ibexa\Contracts\Core\Persistence\Content\MetadataUpdateStruct; | ||||||||||||||||||||||||||||||||||||||||||||||||||
use Ibexa\Contracts\Core\Persistence\Content\Relation; | ||||||||||||||||||||||||||||||||||||||||||||||||||
use Ibexa\Contracts\Core\Persistence\Content\Relation as SPIRelation; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -48,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 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']], | ||||||||||||||||||||||||||||||||||||||||||||||||||
['addRelation', [new RelationCreateStruct(['destinationContentId' => 2, 'sourceContentId' => 4])], [['content', [2], false], ['content', [4], false]], null, ['c-2', 'c-4']], | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -437,27 +439,63 @@ public function providerForCachedLoadMethodsMiss(): array | |||||||||||||||||||||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
public function testDeleteContent() | ||||||||||||||||||||||||||||||||||||||||||||||||||
public function testUpdateContent(): void | ||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
$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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
$this->prepareHandlerMocks( | ||||||||||||||||||||||||||||||||||||||||||||||||||
$innerContentHandlerMock, | ||||||||||||||||||||||||||||||||||||||||||||||||||
$innerLocationHandlerMock, | ||||||||||||||||||||||||||||||||||||||||||||||||||
1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$innerContentHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->once()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->method('loadReverseRelations') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->with(2, APIRelation::FIELD | APIRelation::ASSET) | ||||||||||||||||||||||||||||||||||||||||||||||||||
->willReturn( | ||||||||||||||||||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||||||||||||||||||
new SPIRelation(['sourceContentId' => 42]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||
->method('updateContent') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->with(2, 1, new UpdateStruct()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
->willReturn(new Content()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$this->cacheIdentifierGeneratorMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->exactly(5)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
->method('generateTag') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->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'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+463
to
474
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$innerHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
$this->cacheMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->once()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->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()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
public function testDeleteContent() | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
$this->loggerMock->expects($this->once())->method('logCall'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$innerContentHandlerMock = $this->createMock(SPIContentHandler::class); | ||||||||||||||||||||||||||||||||||||||||||||||||||
$innerLocationHandlerMock = $this->createMock(SPILocationHandler::class); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$this->prepareHandlerMocks( | ||||||||||||||||||||||||||||||||||||||||||||||||||
$innerContentHandlerMock, | ||||||||||||||||||||||||||||||||||||||||||||||||||
$innerLocationHandlerMock, | ||||||||||||||||||||||||||||||||||||||||||||||||||
2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$innerContentHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->once()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->method('deleteContent') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->with(2) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -468,22 +506,68 @@ public function testDeleteContent() | |||||||||||||||||||||||||||||||||||||||||||||||||
->method('deleteItem'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$this->cacheIdentifierGeneratorMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->exactly(2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->exactly(4)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->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); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||
* @param \Ibexa\Contracts\Core\Persistence\Content\Handler|\PHPUnit\Framework\MockObject\MockObject $innerContentHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
* @param \Ibexa\Contracts\Core\Persistence\Content\Location\Handler|\PHPUnit\Framework\MockObject\MockObject $innerLocationHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
private function prepareHandlerMocks( | ||||||||||||||||||||||||||||||||||||||||||||||||||
SPIContentHandler $innerContentHandlerMock, | ||||||||||||||||||||||||||||||||||||||||||||||||||
SPILocationHandler $innerLocationHandlerMock, | ||||||||||||||||||||||||||||||||||||||||||||||||||
int $contentHandlerCount = 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
int $locationHandlerCount = 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
int $loadReverseRelationsCount = 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
int $loadLocationsByContentCount = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||
$this->persistenceHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->exactly($contentHandlerCount)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->method('contentHandler') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->willReturn($innerContentHandlerMock); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$innerContentHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->exactly($loadReverseRelationsCount)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->method('loadReverseRelations') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->with(2, APIRelation::FIELD | APIRelation::ASSET) | ||||||||||||||||||||||||||||||||||||||||||||||||||
->willReturn( | ||||||||||||||||||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||||||||||||||||||
new SPIRelation(['sourceContentId' => 42]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$this->persistenceHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->exactly($locationHandlerCount)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->method('locationHandler') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->willReturn($innerLocationHandlerMock); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
$innerLocationHandlerMock | ||||||||||||||||||||||||||||||||||||||||||||||||||
->expects($this->exactly($loadLocationsByContentCount)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
->method('loadLocationsByContent') | ||||||||||||||||||||||||||||||||||||||||||||||||||
->with(2) | ||||||||||||||||||||||||||||||||||||||||||||||||||
->willReturn( | ||||||||||||||||||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||||||||||||||||||
new Content\Location(['id' => 3]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
new Content\Location(['id' => 4]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
class_alias(ContentHandlerTest::class, 'eZ\Publish\Core\Persistence\Cache\Tests\ContentHandlerTest'); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ | |||||
use Ibexa\Contracts\Core\Persistence\Content\Location\Trash\Handler as TrashHandler; | ||||||
use Ibexa\Contracts\Core\Persistence\Content\Location\Trashed; | ||||||
use Ibexa\Contracts\Core\Persistence\Content\Relation; | ||||||
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; | ||||||
use Ibexa\Contracts\Core\Repository\Values\Content\Trash\TrashItemDeleteResult; | ||||||
use Ibexa\Core\Persistence\Cache\ContentHandler; | ||||||
use Ibexa\Core\Persistence\Cache\LocationHandler; | ||||||
|
@@ -118,10 +119,13 @@ public function testTrashSubtree() | |||||
{ | ||||||
$locationId = 6; | ||||||
$contentId = 42; | ||||||
$versionNo = 1; | ||||||
|
||||||
$tags = [ | ||||||
'c-' . $contentId . '-v-' . $versionNo, | ||||||
'c-' . $contentId, | ||||||
'lp-' . $locationId, | ||||||
'l-' . $locationId, | ||||||
]; | ||||||
|
||||||
$handlerMethodName = $this->getHandlerMethodName(); | ||||||
|
@@ -149,18 +153,29 @@ public function testTrashSubtree() | |||||
->method($handlerMethodName) | ||||||
->willReturn($innerHandler); | ||||||
|
||||||
$contentHandlerMock | ||||||
->expects($this->once()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
->method('listVersions') | ||||||
->with($contentId) | ||||||
->willReturn( | ||||||
[ | ||||||
new VersionInfo(['versionNo' => $versionNo]), | ||||||
] | ||||||
); | ||||||
$innerHandler | ||||||
->expects($this->once()) | ||||||
->method('trashSubtree') | ||||||
->with($locationId) | ||||||
->willReturn(null); | ||||||
|
||||||
$this->cacheIdentifierGeneratorMock | ||||||
->expects($this->exactly(2)) | ||||||
->expects($this->exactly(4)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
->method('generateTag') | ||||||
->withConsecutive( | ||||||
['content_version', [$contentId, $versionNo], false], | ||||||
['content', [$contentId], false], | ||||||
['location_path', [$locationId], false] | ||||||
['location_path', [$locationId], false], | ||||||
['location', [$locationId], false], | ||||||
) | ||||||
->willReturnOnConsecutiveCalls(...$tags); | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While at it, given your changes affect method PHPDoc and signature, could you do full improvement on that?
The signature should now be as follows: