From e68c1fb9e4d5de214c1e483531706ec300ffdb0d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 11 Jul 2012 12:58:57 +0200 Subject: [PATCH] [ticket/10950] Use database count() and group by instead of doing that in php PHPBB3-10950 --- phpBB/includes/functions_privmsgs.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 6c0adccbed..1d45961ac4 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1143,7 +1143,7 @@ function phpbb_delete_user_pms($user_id) if (!empty($undelivered_msg)) { - // A pm is not undelivered, if for any receipt the message was moved + // A pm is delivered, if for any receipt the message was moved // from their NO_BOX to another folder. $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' @@ -1165,23 +1165,17 @@ function phpbb_delete_user_pms($user_id) $undelivered_user = array(); // Count the messages we delete, so we can correct the user pm data - $sql = 'SELECT user_id + $sql = 'SELECT user_id, COUNT(msg_id) as num_undelivered_privmsgs FROM ' . PRIVMSGS_TO_TABLE . ' WHERE author_id = ' . $user_id . ' AND folder_id = ' . PRIVMSGS_NO_BOX . ' - AND ' . $db->sql_in_set('msg_id', $undelivered_msg); + AND ' . $db->sql_in_set('msg_id', $undelivered_msg) . ' + GROUP BY user_id'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - if (isset($undelivered_user[$row['user_id']])) - { - ++$undelivered_user[$row['user_id']]; - } - else - { - $undelivered_user[$row['user_id']] = 1; - } + $undelivered_user[$row['user_id']] = (int) $row['num_undelivered_privmsgs']; } $db->sql_freeresult($result);