Skip to content

Commit

Permalink
Merge pull request #456 from kennethormandy/contacts-batch-query
Browse files Browse the repository at this point in the history
Updates contacts query for large lists
  • Loading branch information
bencroker authored Mar 9, 2024
2 parents 6a3f170 + b58bda0 commit cffeae2
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/services/SendoutsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ public function getPendingRecipients(SendoutElement $sendout): array
*/
public function getPendingRecipientCount(SendoutElement $sendout): int
{
return count($this->getPendingRecipients($sendout)) - $sendout->failures;
if ($sendout->sendoutType === 'regular') {
$count = count($this->_getPendingRecipientsStandardIds($sendout));
} else {
$count = count($this->getPendingRecipients($sendout));
}

return $count - $sendout->failures;
}

/**
Expand Down Expand Up @@ -588,16 +594,24 @@ private function _getSentRecipientsQuery(SendoutElement $sendout, bool $todayOnl
}

/**
* Returns the standard sendout's pending contact IDs.
* Returns the standard sendout’s base query condition.
*/
private function _getPendingRecipientsStandard(SendoutElement $sendout): array
private function _getPendingRecipientsStandardBaseCondition(SendoutElement $sendout): array
{
App::maxPowerCaptain();

$baseCondition = [
return [
'mailingListId' => $sendout->mailingListIds,
'subscriptionStatus' => 'subscribed',
];
}

/**
* Returns the standard sendout’s pending contact IDs.
*/
private function _getPendingRecipientsStandardIds(SendoutElement $sendout): array
{
App::maxPowerCaptain();

$baseCondition = $this->_getPendingRecipientsStandardBaseCondition($sendout);

// Get contacts subscribed to sendout's mailing lists
$query = ContactMailingListRecord::find()
Expand Down Expand Up @@ -633,6 +647,19 @@ private function _getPendingRecipientsStandard(SendoutElement $sendout): array
}
}

return $contactIds;
}

/**
* Returns the standard sendout’s pending contacts.
*/
private function _getPendingRecipientsStandard(SendoutElement $sendout): array
{
App::maxPowerCaptain();

$baseCondition = $this->_getPendingRecipientsStandardBaseCondition($sendout);
$contactIds = $this->_getPendingRecipientsStandardIds($sendout);

// Get recipients as array
return ContactMailingListRecord::find()
->select(['contactId', 'min([[mailingListId]]) as mailingListId', 'min([[subscribed]]) as subscribed'])
Expand Down

0 comments on commit cffeae2

Please sign in to comment.