diff options
author | Joas Schilling <coding@schilljs.com> | 2021-09-29 17:32:59 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-10-11 17:03:32 +0300 |
commit | 06cf1ee5f24a783ba7fe6d658fd403a5220c0ab3 (patch) | |
tree | 31893dc8b79dc860b978c8340bde6299844cfa6f /lib | |
parent | 0eeb451cdb728cbc34ba9d82aa16211dd7c684b9 (diff) |
Introduce a batch size for the mail notifications so it does not consume too much time
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/BackgroundJob/SendNotificationMails.php | 9 | ||||
-rw-r--r-- | lib/MailNotifications.php | 8 |
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/BackgroundJob/SendNotificationMails.php b/lib/BackgroundJob/SendNotificationMails.php index 5960d87..321dc26 100644 --- a/lib/BackgroundJob/SendNotificationMails.php +++ b/lib/BackgroundJob/SendNotificationMails.php @@ -33,13 +33,16 @@ class SendNotificationMails extends TimedJob { protected $mailNotifications; public function __construct(ITimeFactory $timeFactory, - MailNotifications $mailNotifications) { + MailNotifications $mailNotifications, + bool $isCLI) { parent::__construct($timeFactory); $this->mailNotifications = $mailNotifications; + $this->isCLI = $isCLI; } - protected function run($argument) { - $this->mailNotifications->sendEmails(); + protected function run($argument): void { + $batchSize = $this->isCLI ? MailNotifications::BATCH_SIZE_CLI : MailNotifications::BATCH_SIZE_WEB; + $this->mailNotifications->sendEmails($batchSize); } } diff --git a/lib/MailNotifications.php b/lib/MailNotifications.php index 03ec5db..a5960f1 100644 --- a/lib/MailNotifications.php +++ b/lib/MailNotifications.php @@ -75,6 +75,8 @@ class MailNotifications { /** @var ITimeFactory */ protected $timeFactory; + public const BATCH_SIZE_CLI = 500; + public const BATCH_SIZE_WEB = 25; public const DEFAULT_BATCH_TIME = 3600 * 24; public function __construct( @@ -105,12 +107,14 @@ class MailNotifications { /** * Send all due notification emails. + * + * @param int $batchSize */ - public function sendEmails(): void { + public function sendEmails(int $batchSize): void { // Get all users who enabled notification emails. $users = $this->config->getUsersForUserValue('notifications', 'notifications_email_enabled', '1'); - if (count($users) == 0) { + if (empty($users)) { return; } |