Compute change of global subscribed subscribers

[MAILPOET-4828]
This commit is contained in:
Rostislav Wolny
2023-01-20 13:29:09 +01:00
committed by Aschepikov
parent 6e99d5ec9d
commit 04307ca2a6
6 changed files with 70 additions and 26 deletions

View File

@@ -51,18 +51,22 @@ class SubscribersRepository extends Repository {
}
public function getTotalSubscribers(): int {
return $this->getCountOfSubscribersForStates([
SubscriberEntity::STATUS_SUBSCRIBED,
SubscriberEntity::STATUS_UNCONFIRMED,
SubscriberEntity::STATUS_INACTIVE,
]);
}
public function getCountOfSubscribersForStates(array $states): int {
$query = $this->entityManager
->createQueryBuilder()
->select('count(n.id)')
->from(SubscriberEntity::class, 'n')
->where('n.deletedAt IS NULL AND n.status IN (:statuses)')
->setParameter('statuses', [
SubscriberEntity::STATUS_SUBSCRIBED,
SubscriberEntity::STATUS_UNCONFIRMED,
SubscriberEntity::STATUS_INACTIVE,
])
->setParameter('statuses', $states)
->getQuery();
return (int)$query->getSingleScalarResult();
return intval($query->getSingleScalarResult());
}
public function invalidateTotalSubscribersCache(): void {
@@ -390,7 +394,8 @@ class SubscribersRepository extends Repository {
->select('COUNT(s.id)')
->from(StatisticsUnsubscribeEntity::class, 'su')
->join('su.subscriber', 's')
->where('s.createdAt > :unsubscribedAfter')
->where('s.createdAt <= :unsubscribedAfter')
->andWhere('su.createdAt > :unsubscribedAfter')
->andWhere('s.status = :status')
->andWhere('s.deletedAt IS NULL')
->setParameter('unsubscribedAfter', $unsubscribedAfter)