Optimize newsletter reactivation
When reactivating a newsletter with many queues (e.g., a welcome email with a long history)
NewsletterEntity::getQueues may fail because it attempts to fetch all queues and instantiate
many entity objects.
In this commit, I optimize this by looking only into unfinished queues.
getUnfinishedQueues look for where countToProcess is higher than 0.
We set the count for welcome emails when we create a new queue
see f1ffc77bf3/mailpoet/lib/Newsletter/Scheduler/WelcomeScheduler.php (L140)
[MAILPOET-6310]
This commit is contained in:
committed by
Aschepikov
parent
1c3ea9cd0a
commit
3fbff8c83f
@@ -215,7 +215,7 @@ class Newsletters extends APIEndpoint {
|
||||
|
||||
// if there are paused tasks unpause them
|
||||
if ($newsletter->getStatus() === NewsletterEntity::STATUS_ACTIVE) {
|
||||
$queues = $newsletter->getQueues();
|
||||
$queues = $newsletter->getUnfinishedQueues();
|
||||
foreach ($queues as $queue) {
|
||||
$task = $queue->getTask();
|
||||
if ($task && $task->getStatus() === ScheduledTaskEntity::STATUS_PAUSED) {
|
||||
|
@@ -537,7 +537,7 @@ class NewsletterEntity {
|
||||
/**
|
||||
* @return Collection<int, SendingQueueEntity>
|
||||
*/
|
||||
private function getUnfinishedQueues(): Collection {
|
||||
public function getUnfinishedQueues(): Collection {
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$criteria->where($expr->neq('countToProcess', 0));
|
||||
|
@@ -290,7 +290,8 @@ class NewslettersTest extends \MailPoetTest {
|
||||
SendingQueueWorker::TASK_TYPE,
|
||||
ScheduledTaskEntity::STATUS_PAUSED,
|
||||
);
|
||||
(new SendingQueueFactory())->create($scheduledTask1, $this->postNotification);
|
||||
$queue = (new SendingQueueFactory())->create($scheduledTask1, $this->postNotification);
|
||||
$queue->setCountToProcess(1);
|
||||
$segment = $this->segmentRepository->createOrUpdate('Segment 1');
|
||||
$this->createNewsletterSegment($this->postNotification, $segment);
|
||||
|
||||
|
Reference in New Issue
Block a user