-
Notifications
You must be signed in to change notification settings - Fork 15
IBX-5502: Added additional tag cleaning to limit down number of orphaned tag en… #477
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
base: 4.6
Are you sure you want to change the base?
Changes from all commits
6e60c00
06b7bce
e6ce8b7
6536532
b501ee2
d597ba7
a71ea65
d46a8f6
e8b66fc
c6eb694
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -329,18 +329,40 @@ public function updateMetadata($contentId, MetadataUpdateStruct $struct) | |||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* {@inheritdoc} | ||||||||||||||||||||||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||||||||||||||||||||||
* @throws \Psr\Cache\InvalidArgumentException | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public function updateContent($contentId, $versionNo, UpdateStruct $struct) | ||||||||||||||||||||||
public function updateContent($contentId, $versionNo, UpdateStruct $struct): Content | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
$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. 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.
Only in the empirical way. If you have dozens or hundreds of locations, ofc this can have an impact, but then, probably this one is less of your worry then.
Any explanation behind this one? The change is made in a handler, not in the caching system, which to be frank main purpose is to do "loads".
That's, in my opinion is a wrong approach. This helps to clear unevictable memory from Redis - not doing this always results in eventually reaching a point when the whole app crashes. So this is not memory vs longer updates, but making the project less prone to failure due to OOM errors. |
||||||||||||||||||||||
$locationTags = array_map(function (Content\Location $location): string { | ||||||||||||||||||||||
return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$location->id]); | ||||||||||||||||||||||
}, $locations); | ||||||||||||||||||||||
Comment on lines
+340
to
+342
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
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. Well, to be honest in my opinion thi is even less readable ;) But no strong opinion here. |
||||||||||||||||||||||
$locationPathTags = array_map(function (Content\Location $location): string { | ||||||||||||||||||||||
return $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$location->id]); | ||||||||||||||||||||||
}, $locations); | ||||||||||||||||||||||
Comment on lines
+343
to
+345
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 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. As mentioned in the PR's description, the list presented only has an example, and the number of orphaned tags is not limited to it. But if you look really closely, you will also find mention of the |
||||||||||||||||||||||
|
||||||||||||||||||||||
$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. 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's true, and I agree. Any suggestionson how we can handle 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. ping @alongosz |
||||||||||||||||||||||
); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
$tags = array_merge( | ||||||||||||||||||||||
$locationTags, | ||||||||||||||||||||||
$locationPathTags, | ||||||||||||||||||||||
$versionTags | ||||||||||||||||||||||
); | ||||||||||||||||||||||
$this->cache->invalidateTags($tags); | ||||||||||||||||||||||
Comment on lines
+360
to
+365
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? 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. I do not agree, |
||||||||||||||||||||||
|
||||||||||||||||||||||
return $content; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
@@ -357,6 +379,7 @@ public function deleteContent($contentId) | |||||||||||||||||||||
$contentId, | ||||||||||||||||||||||
APIRelation::FIELD | APIRelation::ASSET | ||||||||||||||||||||||
); | ||||||||||||||||||||||
$contentLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); | ||||||||||||||||||||||
|
||||||||||||||||||||||
$return = $this->persistenceHandler->contentHandler()->deleteContent($contentId); | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -372,6 +395,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))); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.