From 3e0270d0cff96a9696211570528f521789913f00 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 7 Jan 2025 11:54:11 +0700 Subject: [PATCH] [ticket/17135] Optimize save_queue() method calls PHPBB-17135 --- phpBB/includes/acp/acp_email.php | 12 +++++++----- phpBB/includes/acp/acp_inactive.php | 14 +++++++++----- phpBB/includes/ucp/ucp_resend.php | 11 ++++++++--- .../phpbb/notification/method/messenger_base.php | 16 ++++++++++------ 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/phpBB/includes/acp/acp_email.php b/phpBB/includes/acp/acp_email.php index 446067c2a8..00ce89317c 100644 --- a/phpBB/includes/acp/acp_email.php +++ b/phpBB/includes/acp/acp_email.php @@ -265,16 +265,18 @@ class acp_email } $errored = !$messenger_method->send() || $errored; - if ($use_queue) - { - $messenger_method->save_queue(); - } } } } unset($email_list); - $messenger->save_queue(); + if ($use_queue) + { + foreach ($messenger_collection_iterator as $messenger_method) + { + $messenger_method->save_queue(); + } + } if ($generate_log_entry) { diff --git a/phpBB/includes/acp/acp_inactive.php b/phpBB/includes/acp/acp_inactive.php index ec74d59169..b9ff966b6d 100644 --- a/phpBB/includes/acp/acp_inactive.php +++ b/phpBB/includes/acp/acp_inactive.php @@ -194,15 +194,15 @@ class acp_inactive $result = $db->sql_query($sql); + /** @var \phpbb\di\service_collection */ + $messenger = $phpbb_container->get('messenger.method_collection'); + $messenger_collection_iterator = $messenger->getIterator(); + if ($row = $db->sql_fetchrow($result)) { // Send the messages $usernames = $user_ids = array(); - /** @var \phpbb\di\service_collection */ - $messenger = $phpbb_container->get('messenger.method_collection'); - $messenger_collection_iterator = $messenger->getIterator(); - do { foreach ($messenger_collection_iterator as $messenger_method) @@ -219,7 +219,6 @@ class acp_inactive ]); $messenger_method->send(); - $messenger_method->save_queue(); } } @@ -242,6 +241,11 @@ class acp_inactive } $db->sql_freeresult($result); + foreach ($messenger_collection_iterator as $messenger_method) + { + $messenger_method->save_queue(); + } + // For remind we really need to redirect, else a refresh can result in more than one reminder $u_action = $this->u_action . "&$u_sort_param&start=$start"; $u_action .= ($per_page != $config['topics_per_page']) ? "&users_per_page=$per_page" : ''; diff --git a/phpBB/includes/ucp/ucp_resend.php b/phpBB/includes/ucp/ucp_resend.php index 4c9c1a86c6..76e748e85d 100644 --- a/phpBB/includes/ucp/ucp_resend.php +++ b/phpBB/includes/ucp/ucp_resend.php @@ -133,6 +133,8 @@ class ucp_resend WHERE ' . $db->sql_in_set('user_id', $admin_ary[0]['a_user']); $result = $db->sql_query($sql); + /** @var \phpbb\di\service_collection */ + $messenger = $phpbb_container->get('messenger.method_collection'); $messenger_collection_iterator = $messenger->getIterator(); while ($row = $db->sql_fetchrow($result)) { @@ -151,13 +153,16 @@ class ucp_resend ]); $messenger_method->send(); - - // Save the queue in the messenger method class (has to be called or these messages could be lost) - $messenger_method->save_queue(); } } } $db->sql_freeresult($result); + + // Save the queue in the messenger method class (has to be called or these messages could be lost) + foreach ($messenger_collection_iterator as $messenger_method) + { + $messenger_method->save_queue(); + } } $this->update_activation_expiration(); diff --git a/phpBB/phpbb/notification/method/messenger_base.php b/phpBB/phpbb/notification/method/messenger_base.php index ca93f4c8a2..e4b97b7cac 100644 --- a/phpBB/phpbb/notification/method/messenger_base.php +++ b/phpBB/phpbb/notification/method/messenger_base.php @@ -86,7 +86,7 @@ abstract class messenger_base extends \phpbb\notification\method\base $user_ids[] = $notification->user_id; } - // We do not send emails to banned users + // We do not notify banned users if (!function_exists('phpbb_get_banned_user_ids')) { include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); @@ -96,7 +96,9 @@ abstract class messenger_base extends \phpbb\notification\method\base // Load all the users we need $this->user_loader->load_users(array_diff($user_ids, $banned_users), array(USER_IGNORE)); - // Time to go through the queue and send emails + // Time to go through the queue and send notifications + $messenger_collection_iterator = $this->messenger->getIterator(); + /** @var type_interface $notification */ foreach ($this->queue as $notification) { @@ -112,7 +114,6 @@ abstract class messenger_base extends \phpbb\notification\method\base continue; } - $messenger_collection_iterator = $this->messenger->getIterator(); foreach ($messenger_collection_iterator as $messenger_method) { if ($messenger_method->get_id() == $notify_method || $notify_method == $messenger_method::NOTIFY_BOTH) @@ -125,13 +126,16 @@ abstract class messenger_base extends \phpbb\notification\method\base ], $notification->get_email_template_variables())); $messenger_method->send(); - - // Save the queue in the messenger method class (has to be called or these messages could be lost) - $messenger_method->save_queue(); } } } + // Save the queue in the messenger method class (has to be called or these messages could be lost) + foreach ($messenger_collection_iterator as $messenger_method) + { + $messenger_method->save_queue(); + } + // We're done, empty the queue $this->empty_queue(); }