aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-03-27 17:29:03 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-03-27 17:29:03 +0200
commit0397b462174887bda3fea4bcebf9a26f6b591a3e (patch)
treefd6479025f20765148ca10fe3bdfe25506407a25 /phpBB/includes
parent9c8aab4d32a001ae66fe005b7124737fc5ad7dd6 (diff)
downloadforums-0397b462174887bda3fea4bcebf9a26f6b591a3e.tar
forums-0397b462174887bda3fea4bcebf9a26f6b591a3e.tar.gz
forums-0397b462174887bda3fea4bcebf9a26f6b591a3e.tar.bz2
forums-0397b462174887bda3fea4bcebf9a26f6b591a3e.tar.xz
forums-0397b462174887bda3fea4bcebf9a26f6b591a3e.zip
[ticket/10605] Split query to be able to use indexes
PHPBB3-10605
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions_privmsgs.php34
1 files changed, 31 insertions, 3 deletions
diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php
index 576da4d439..dd81e8f92d 100644
--- a/phpBB/includes/functions_privmsgs.php
+++ b/phpBB/includes/functions_privmsgs.php
@@ -1098,11 +1098,11 @@ function phpbb_delete_user_pms($user_id)
}
// Get PM Information for later deleting
+ // The two queries where split, so we can use our indexes
+ // Part 1: get PMs the user received
$sql = 'SELECT msg_id, author_id, folder_id, pm_unread, pm_new
FROM ' . PRIVMSGS_TO_TABLE . '
- WHERE user_id = ' . $user_id . '
- OR (author_id = ' . $user_id . '
- AND folder_id = ' . PRIVMSGS_NO_BOX . ')';
+ WHERE user_id = ' . $user_id;
$result = $db->sql_query($sql);
$undelivered_msg = $undelivered_user = $delete_ids = array();
@@ -1127,6 +1127,34 @@ function phpbb_delete_user_pms($user_id)
}
$db->sql_freeresult($result);
+ // Part 2: get PMs the user sent
+ $sql = 'SELECT msg_id, author_id, folder_id, pm_unread, pm_new
+ FROM ' . PRIVMSGS_TO_TABLE . '
+ WHERE author_id = ' . $user_id . '
+ AND folder_id = ' . PRIVMSGS_NO_BOX;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($row['author_id'] == $user_id && $row['folder_id'] == PRIVMSGS_NO_BOX)
+ {
+ // Undelivered messages
+ $undelivered_msg[] = $row['msg_id'];
+
+ if (isset($undelivered_user[$row['user_id']]))
+ {
+ ++$undelivered_user[$row['user_id']];
+ }
+ else
+ {
+ $undelivered_user[$row['user_id']] = 1;
+ }
+ }
+
+ $delete_ids[(int) $row['msg_id']] = (int) $row['msg_id'];
+ }
+ $db->sql_freeresult($result);
+
if (empty($delete_ids))
{
return false;