Add cleanup subscribers counts cache
[MAILPOET-3714]
This commit is contained in:
@ -259,6 +259,8 @@ class Settings extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->subscribersCountsController->recalculateSubscribersWithoutSegmentStatisticsCache();
|
$this->subscribersCountsController->recalculateSubscribersWithoutSegmentStatisticsCache();
|
||||||
|
// remove redundancies from cache
|
||||||
|
$this->subscribersCountsController->removeRedundancyFromStatisticsCache();
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class TransientCache {
|
|||||||
$this->wp->setTransient($key, $items);
|
$this->wp->setTransient($key, $items);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getItems(string $key): array {
|
public function getItems(string $key): array {
|
||||||
return $this->wp->getTransient($key) ?: [];
|
return $this->wp->getTransient($key) ?: [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,9 @@ class SubscribersCountCacheRecalculation extends SimpleWorker {
|
|||||||
// update cache for subscribers without segment
|
// update cache for subscribers without segment
|
||||||
$this->recalculateSegmentCache($timer, 0);
|
$this->recalculateSegmentCache($timer, 0);
|
||||||
|
|
||||||
|
// remove redundancies from cache
|
||||||
|
$this->subscribersCountsController->removeRedundancyFromStatisticsCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,4 +90,21 @@ class SubscribersCountsController {
|
|||||||
$this->transientCache->setItem(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY, $result, 0);
|
$this->transientCache->setItem(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY, $result, 0);
|
||||||
return $result;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user