Cache total subscribers count, add tests
[MAILPOET-4416]
This commit is contained in:
@@ -7,6 +7,7 @@ use MailPoet\Entities\SegmentEntity;
|
||||
use MailPoet\Entities\SubscriberCustomFieldEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\Entities\SubscriberSegmentEntity;
|
||||
use MailPoet\Util\License\Features\Subscribers;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
use MailPoetVendor\Carbon\CarbonImmutable;
|
||||
@@ -41,10 +42,7 @@ class SubscribersRepository extends Repository {
|
||||
return SubscriberEntity::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSubscribers() {
|
||||
public function getTotalSubscribers(): int {
|
||||
$query = $this->entityManager
|
||||
->createQueryBuilder()
|
||||
->select('count(n.id)')
|
||||
@@ -59,6 +57,10 @@ class SubscribersRepository extends Repository {
|
||||
return (int)$query->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function invalidateTotalSubscribersCache(): void {
|
||||
$this->wp->deleteTransient(Subscribers::SUBSCRIBERS_COUNT_CACHE_KEY);
|
||||
}
|
||||
|
||||
public function findBySegment(int $segmentId): array {
|
||||
return $this->entityManager
|
||||
->createQueryBuilder()
|
||||
@@ -116,6 +118,7 @@ class SubscribersRepository extends Repository {
|
||||
->setParameter('ids', $ids)
|
||||
->getQuery()->execute();
|
||||
|
||||
$this->invalidateTotalSubscribersCache();
|
||||
return count($ids);
|
||||
}
|
||||
|
||||
@@ -135,6 +138,7 @@ class SubscribersRepository extends Repository {
|
||||
->setParameter('ids', $ids)
|
||||
->getQuery()->execute();
|
||||
|
||||
$this->invalidateTotalSubscribersCache();
|
||||
return count($ids);
|
||||
}
|
||||
|
||||
@@ -171,6 +175,7 @@ class SubscribersRepository extends Repository {
|
||||
->getQuery()->execute();
|
||||
});
|
||||
|
||||
$this->invalidateTotalSubscribersCache();
|
||||
return $count;
|
||||
}
|
||||
|
||||
@@ -282,6 +287,7 @@ class SubscribersRepository extends Repository {
|
||||
->setParameter('ids', $ids)
|
||||
->getQuery()->execute();
|
||||
|
||||
$this->invalidateTotalSubscribersCache();
|
||||
return count($ids);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user