Skip to content

Commit

Permalink
Refactor to SendoutBatcher
Browse files Browse the repository at this point in the history
commit eb6e2a3
Author: bencroker <[email protected]>
Date:   Sat Mar 9 10:24:17 2024 -0600

    Deprecate methods

commit 681276f
Author: bencroker <[email protected]>
Date:   Sat Mar 9 10:13:10 2024 -0600

    Fix SendoutBatcher implementation, curly quotes

commit afdd7b4
Author: bencroker <[email protected]>
Date:   Sat Mar 9 09:08:29 2024 -0600

    Revert method removal

commit 372ce05
Author: bencroker <[email protected]>
Date:   Sat Mar 9 08:57:58 2024 -0600

    Refactor to SendoutBatcher

commit 8b791ce
Author: bencroker <[email protected]>
Date:   Sat Mar 9 08:54:59 2024 -0600

    Adds faster calculation of expected recipients

    commit d641372
    Author: bencroker <[email protected]>
    Date:   Fri Mar 8 20:24:19 2024 -0600

        Revert the fix, back to square 1

    commit cffeae2
    Merge: 6a3f170 b58bda0
    Author: Ben Croker <[email protected]>
    Date:   Fri Mar 8 19:42:20 2024 -0600

        Merge pull request #456 from kennethormandy/contacts-batch-query

        Updates contacts query for large lists

    commit 6a3f170
    Author: bencroker <[email protected]>
    Date:   Fri Mar 8 19:36:05 2024 -0600

        Fix too many parameters

        MySQL acccepts at most 65535 parameters, so it is important to use a `where` clause here.

    commit b58bda0
    Author: Ben Croker <[email protected]>
    Date:   Fri Mar 8 19:31:31 2024 -0600

        Remove batching, code cleanup

    commit d267fbe
    Author: Ben Croker <[email protected]>
    Date:   Fri Mar 8 18:54:44 2024 -0600

        Revert changes

    commit 57e808a
    Merge: 4b83e5c f289a4b
    Author: Ben Croker <[email protected]>
    Date:   Fri Mar 8 18:45:24 2024 -0600

        Merge pull request #455 from kennethormandy/bugfix/missing-preflight-twig-variables

        Fixes missing memory limit and time limit Twig variables

    commit db87912
    Author: Kenneth Ormandy <[email protected]>
    Date:   Fri Mar 8 12:46:58 2024 -0800

        Adds batch query when querying regular sendout recipients

    commit 11cfb80
    Author: Kenneth Ormandy <[email protected]>
    Date:   Fri Mar 8 12:44:26 2024 -0800

        Adds faster calculation of expected recipients for regular sendouts
  • Loading branch information
bencroker committed Mar 9, 2024
1 parent f289a4b commit c9e1fc1
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 121 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@

- Campaign now requires Craft CMS 4.4.0 or later.

### Fixed

- Fixed a bug in which the expected recipients count could fail in sendouts with very large numbers of contacts.

### Deprecated

- Deprecated the `memoryLimit` config setting.
- Deprecated the `memoryThreshold` config setting.
- Deprecated the `timeLimit` config setting.
- Deprecated the `timeThreshold` config setting.
- Deprecated the `Campaign::maxPowerLieutenant()` method. Use `App:maxPowerCaptain()` instead.
- Deprecated the `SendoutElement::getPendingRecipients()` method. Use `Campaign::$plugin->sendouts->getPendingRecipients()` instead.
- Deprecated the `SendoutElement::getPendingRecipientCount()` method. Use `Campaign::$plugin->sendouts->getPendingRecipients()` instead.

## 2.12.2 - 2024-03-05

Expand Down
33 changes: 0 additions & 33 deletions src/batchers/PendingRecipientBatcher.php

This file was deleted.

41 changes: 41 additions & 0 deletions src/batchers/SendoutBatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace putyourlightson\campaign\batchers;

use craft\base\Batchable;
use putyourlightson\campaign\Campaign;
use putyourlightson\campaign\elements\SendoutElement;

/**
* @since 2.13.0
*/
class SendoutBatcher implements Batchable
{
public function __construct(
private ?SendoutElement $sendout,
) {
}

/**
* @inheritdoc
*/
public function count(): int
{
if ($this->sendout === null) {
return 0;
}

// Return the number of pending plus sent recipients.
$pendingRecipientCount = Campaign::$plugin->sendouts->getPendingRecipientCount($this->sendout);

return $pendingRecipientCount + $this->sendout->recipients;
}

/**
* Returns a batch of pending recipients, using the limit and ignoring the offset, since the pending recipients array is calculated fresh each time.
*/
public function getSlice(int $offset, int $limit): iterable
{
return Campaign::$plugin->sendouts->getPendingRecipients($this->sendout, $limit);
}
}
2 changes: 1 addition & 1 deletion src/controllers/ExportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function actionExportFile(): ?Response
return $this->asModelFailure($export, Craft::t('campaign', 'Couldn’t export file.'), 'export');
}

Campaign::$plugin->log('File exported by "{username}".');
Campaign::$plugin->log('File exported by {username}.');

return $this->response->sendFile($export->filePath);
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/ImportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function actionImportFile(): ?Response
}
}

Campaign::$plugin->log('CSV file "{fileName}" imported by "{username}".', [
Campaign::$plugin->log('CSV file "{fileName}" imported by {username}.', [
'fileName' => $import->fileName,
]);

Expand Down Expand Up @@ -216,7 +216,7 @@ public function actionImportUserGroup(): ?Response
}
}

Campaign::$plugin->log('User group "{userGroup}" imported by "{username}".', [
Campaign::$plugin->log('User group "{userGroup}" imported by {username}.', [
'userGroup' => $import->getUserGroup()->name,
]);

Expand Down
8 changes: 4 additions & 4 deletions src/controllers/SendoutsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function actionQueuePendingSendouts(): Response
public function actionGetPendingRecipientCount(): Response
{
$sendout = $this->_getSendoutFromParamId();
$this->response->content = (string)$sendout->getPendingRecipientCount();
$this->response->content = (string)Campaign::$plugin->sendouts->getPendingRecipientCount($sendout);

return $this->response;
}
Expand Down Expand Up @@ -262,7 +262,7 @@ public function actionSend(): ?Response
return $this->asModelFailure($sendout, Craft::t('campaign', 'Couldn’t save sendout.'), 'sendout');
}

Campaign::$plugin->log('Sendout "{title}" initiated by "{username}".', [
Campaign::$plugin->log('Sendout {title} initiated by {username}.', [
'title' => $sendout->title,
]);

Expand Down Expand Up @@ -311,7 +311,7 @@ public function actionPause(): ?Response
return $this->asFailure(Craft::t('campaign', 'Sendout could not be paused.'));
}

Campaign::$plugin->log('Sendout "{title}" paused by "{username}".', [
Campaign::$plugin->log('Sendout {title} paused by {username}.', [
'title' => $sendout->title,
]);

Expand All @@ -331,7 +331,7 @@ public function actionCancel(): ?Response
return $this->asFailure(Craft::t('campaign', 'Sendout could not be cancelled.'));
}

Campaign::$plugin->log('Sendout "{title}" cancelled by "{username}".', [
Campaign::$plugin->log('Sendout {title} cancelled by {username}.', [
'title' => $sendout->title,
]);

Expand Down
Loading

0 comments on commit c9e1fc1

Please sign in to comment.