Add cleanup subscribers counts cache

[MAILPOET-3714]
This commit is contained in:
Jan Lysý
2021-07-23 15:19:41 +02:00
committed by Veljko V
parent 2deaeb284b
commit 19fad073d0
4 changed files with 23 additions and 1 deletions

View File

@@ -90,4 +90,21 @@ class SubscribersCountsController {
$this->transientCache->setItem(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY, $result, 0);
return $result;
}
public function removeRedundancyFromStatisticsCache() {
$segments = $this->segmentsRepository->findAll();
$segmentIds = array_map(function (SegmentEntity $segment): int {
return (int)$segment->getId();
}, $segments);
foreach ($this->transientCache->getItems(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY) as $id => $item) {
if (!in_array($id, $segmentIds)) {
$this->transientCache->invalidateItem(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY, $id);
}
}
foreach ($this->transientCache->getItems(TransientCache::SUBSCRIBERS_GLOBAL_STATUS_STATISTICS_COUNT_KEY) as $id => $item) {
if (!in_array($id, $segmentIds)) {
$this->transientCache->invalidateItem(TransientCache::SUBSCRIBERS_GLOBAL_STATUS_STATISTICS_COUNT_KEY, $id);
}
}
}
}