Skip to content

Commit

Permalink
Remove batching, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker authored Mar 9, 2024
1 parent d267fbe commit b58bda0
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/services/SendoutsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ public function getPendingRecipients(SendoutElement $sendout): array
*/
public function getPendingRecipientCount(SendoutElement $sendout): int
{
$count = 0;

// TODO Do this for all sendout types, so only IDs are queried at this stage
if ($sendout->sendoutType == 'regular') {
if ($sendout->sendoutType === 'regular') {
$count = count($this->_getPendingRecipientsStandardIds($sendout));
} else {
$count = count($this->getPendingRecipients($sendout));
Expand Down Expand Up @@ -597,16 +594,14 @@ private function _getSentRecipientsQuery(SendoutElement $sendout, bool $todayOnl
}

/**
* Returns the standard sendout’s shared base query condition config.
* Returns the standard sendout’s base query condition.
*/
private function _getPendingRecipientsStandardBaseCondition(SendoutElement $sendout): array
{
$baseCondition = [
return [
'mailingListId' => $sendout->mailingListIds,
'subscriptionStatus' => 'subscribed',
];

return $baseCondition;
}

/**
Expand Down Expand Up @@ -665,23 +660,15 @@ private function _getPendingRecipientsStandard(SendoutElement $sendout): array
$baseCondition = $this->_getPendingRecipientsStandardBaseCondition($sendout);
$contactIds = $this->_getPendingRecipientsStandardIds($sendout);

$contacts = [];

// Get recipients as array
$contactsQuery = ContactMailingListRecord::find()
return ContactMailingListRecord::find()
->select(['contactId', 'min([[mailingListId]]) as mailingListId', 'min([[subscribed]]) as subscribed'])
->groupBy('contactId')
->where($baseCondition)
->andWhere(['contactId' => $contactIds])
->orderBy(['contactId' => SORT_ASC])
->asArray();

// Fetch 10,000 contacts at a time
foreach($contactsQuery->each(10000) as $contact) {
$contacts[] = $contact;
}

return $contacts;
->asArray()
->all();
}

/**
Expand Down

0 comments on commit b58bda0

Please sign in to comment.