Fix counts cache update for below minimum subscribers

[MAILPOET-5390]
This commit is contained in:
alex-mailpoet
2023-06-15 20:22:26 +03:00
committed by Veljko V
parent f78b0f3d3c
commit 3b2d60bb4f
2 changed files with 7 additions and 3 deletions

View File

@@ -125,7 +125,11 @@ class PageRenderer {
$wpSegmentState = ($wpSegment instanceof SegmentEntity) && $wpSegment->getDeletedAt() === null ?
SegmentEntity::SEGMENT_ENABLED : SegmentEntity::SEGMENT_DISABLED;
$installedAtDiff = (new \DateTime($this->settings->get('installed_at')))->diff(new \DateTime());
$subscribersCacheCreatedAt = $this->transientCache->getOldestCreatedAt(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY) ?: Carbon::now();
$subscriberCount = $this->subscribersFeature->getSubscribersCount();
$subscribersCacheCreatedAt = Carbon::now();
if ($this->subscribersFeature->isSubscribersCountEnoughForCache($subscriberCount)) {
$subscribersCacheCreatedAt = $this->transientCache->getOldestCreatedAt(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY) ?: Carbon::now();
}
$defaults = [
'current_page' => sanitize_text_field(wp_unslash($_GET['page'] ?? '')),
@@ -167,7 +171,7 @@ class PageRenderer {
'mss_active' => $this->bridge->isMailpoetSendingServiceEnabled(),
'plugin_partial_key' => $this->servicesChecker->generatePartialApiKey(),
'mailpoet_hide_automations' => $this->servicesChecker->isBundledSubscription() && $this->wp->isPluginActive('automatewoo/automatewoo.php'),
'subscriber_count' => $this->subscribersFeature->getSubscribersCount(),
'subscriber_count' => $subscriberCount,
'subscribers_counts_cache_created_at' => $subscribersCacheCreatedAt->format('Y-m-d\TH:i:sO'),
'subscribers_limit' => $this->subscribersFeature->getSubscribersLimit(),
'subscribers_limit_reached' => $this->subscribersFeature->check(),