Optimize group member logic in the group log event subscriber.
This commit is contained in:
parent
0df2e5b471
commit
937001a13a
|
@ -167,31 +167,31 @@ class LogEventSubscriber implements EventSubscriberInterface {
|
||||||
// @todo Only invalidate cache if the movement log changes the group's current location. This might be different for each asset.
|
// @todo Only invalidate cache if the movement log changes the group's current location. This might be different for each asset.
|
||||||
$tags = [];
|
$tags = [];
|
||||||
|
|
||||||
// Include assets that were previously referenced.
|
// Include group assets that were previously referenced.
|
||||||
if (!empty($log->original)) {
|
if (!empty($log->original)) {
|
||||||
foreach ($log->original->get('asset')->referencedEntities() as $asset) {
|
|
||||||
|
|
||||||
// If the asset is a group asset, collect group member cache tags.
|
// Get all group assets.
|
||||||
if ($asset->bundle() === 'group') {
|
$group_assets = array_filter($log->original->get('asset')->referencedEntities(), function (AssetInterface $asset) {
|
||||||
$member_tags = array_map(function (AssetInterface $asset) {
|
return $asset->bundle() === 'group';
|
||||||
return $asset->getCacheTags();
|
});
|
||||||
}, $this->groupMembership->getGroupMembers([$asset]));
|
|
||||||
array_push($tags, ...array_merge(...$member_tags));
|
// Collect group member cache tags.
|
||||||
}
|
$member_tags = array_map(function (AssetInterface $asset) {
|
||||||
}
|
return $asset->getCacheTags();
|
||||||
|
}, $this->groupMembership->getGroupMembers($group_assets));
|
||||||
|
array_push($tags, ...array_merge(...$member_tags));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include assets currently referenced by the log.
|
// Include group assets currently referenced by the log.
|
||||||
foreach ($log->get('asset')->referencedEntities() as $asset) {
|
$group_assets = array_filter($log->get('asset')->referencedEntities(), function (AssetInterface $asset) {
|
||||||
|
return $asset->bundle() === 'group';
|
||||||
|
});
|
||||||
|
|
||||||
// If the asset is a group asset, collect group member cache tags.
|
// Collect group member cache tags.
|
||||||
if ($asset->bundle() === 'group') {
|
$member_tags = array_map(function (AssetInterface $asset) {
|
||||||
$member_tags = array_map(function (AssetInterface $asset) {
|
return $asset->getCacheTags();
|
||||||
return $asset->getCacheTags();
|
}, $this->groupMembership->getGroupMembers($group_assets));
|
||||||
}, $this->groupMembership->getGroupMembers([$asset]));
|
array_push($tags, ...array_merge(...$member_tags));
|
||||||
array_push($tags, ...array_merge(...$member_tags));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invalidate the cache tags.
|
// Invalidate the cache tags.
|
||||||
$this->cacheTagsInvalidator->invalidateTags($tags);
|
$this->cacheTagsInvalidator->invalidateTags($tags);
|
||||||
|
|
Loading…
Reference in New Issue