Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-09-29 17:32:59 +0300
committerJoas Schilling <coding@schilljs.com>2021-10-11 17:03:32 +0300
commit06cf1ee5f24a783ba7fe6d658fd403a5220c0ab3 (patch)
tree31893dc8b79dc860b978c8340bde6299844cfa6f /lib
parent0eeb451cdb728cbc34ba9d82aa16211dd7c684b9 (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.php9
-rw-r--r--lib/MailNotifications.php8
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;
}