diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2012-07-16 17:22:10 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2012-07-16 17:22:10 +0200 |
commit | d9a32ce6143be27b8414072694c969fa16b5329a (patch) | |
tree | 06010ebbb2c020bfa26b0afb8b62e655da00c931 /phpBB/includes/functions_privmsgs.php | |
parent | d883535b102ffba8781f485ba94fae237d8376b0 (diff) | |
download | forums-d9a32ce6143be27b8414072694c969fa16b5329a.tar forums-d9a32ce6143be27b8414072694c969fa16b5329a.tar.gz forums-d9a32ce6143be27b8414072694c969fa16b5329a.tar.bz2 forums-d9a32ce6143be27b8414072694c969fa16b5329a.tar.xz forums-d9a32ce6143be27b8414072694c969fa16b5329a.zip |
[ticket/10950] Update undelivered pm counts in batches not 1 by 1 for each user
PHPBB3-10950
Diffstat (limited to 'phpBB/includes/functions_privmsgs.php')
-rw-r--r-- | phpBB/includes/functions_privmsgs.php | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 1d45961ac4..82344d1787 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1175,16 +1175,29 @@ function phpbb_delete_user_pms($user_id) while ($row = $db->sql_fetchrow($result)) { - $undelivered_user[$row['user_id']] = (int) $row['num_undelivered_privmsgs']; + $num_pms = (int) $row['num_undelivered_privmsgs']; + $undelivered_user[$num_pms][] = (int) $row['user_id']; + + if (sizeof($undelivered_user[$num_pms]) > 50) + { + // If there are too many users affected the query might get + // too long, so we update the value for the first bunch here. + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_new_privmsg = user_new_privmsg - ' . $num_pms . ', + user_unread_privmsg = user_unread_privmsg - ' . $num_pms . ' + WHERE ' . $db->sql_in_set('user_id', $undelivered_user[$num_pms]); + $db->sql_query($sql); + unset($undelivered_user[$num_pms]); + } } $db->sql_freeresult($result); - foreach ($undelivered_user as $undelivered_user_id => $count) + foreach ($undelivered_user as $num_pms => $undelivered_user_set) { $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_new_privmsg = user_new_privmsg - ' . $count . ', - user_unread_privmsg = user_unread_privmsg - ' . $count . ' - WHERE user_id = ' . $undelivered_user_id; + SET user_new_privmsg = user_new_privmsg - ' . $num_pms . ', + user_unread_privmsg = user_unread_privmsg - ' . $num_pms . ' + WHERE ' . $db->sql_in_set('user_id', $undelivered_user_set); $db->sql_query($sql); } |