Ticket #905 (fixed bug)
Merging topics hangs when users are subscribed
- Created: 2013-09-28 08:39:03
- Reported by: Storlek
- Assigned to: quy
- Milestone: 1.5.5
- Component: code
- Priority: normal
If someone is subscribed to a topic that's being merged, the process grinds to a halt because $db->result returns the first row repeatedly. I can confirm that this breaks with both Postgres and SQLite. I'm guessing behavior is different with the MySQL backend, or else this probably would have been noticed and fixed by this point.
Here's a patch:
diff -r 7311cd9bbb32 -r c6081db4ac0b moderate.php
--- a/moderate.php Wed Sep 18 16:07:00 2013 -0400
+++ b/moderate.php Sat Sep 28 04:23:39 2013 -0400
@@ -580,12 +580,11 @@
$db->query('UPDATE '.$db->prefix.'posts SET topic_id='.$merge_to_tid.' WHERE topic_id IN('.implode(',', $topics).')') or error('Unable to merge the posts into the topic', __FILE__, __LINE__, $db->error());
// Update any subscriptions
- $result = $db->query('SELECT user_id FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to fetch subscriptions of merged topics', __FILE__, __LINE__, $db->error());
+ $result = $db->query('SELECT DISTINCT user_id FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to fetch subscriptions of merged topics', __FILE__, __LINE__, $db->error());
- $subscribed_users = array();
- while ($cur_user_id = $db->result($result))
- $subscribed_users[] = $cur_user_id;
- $subscribed_users = array_unique($subscribed_users);
+ $subscribed_users = array();
+ while ($row = $db->fetch_row($result))
+ $subscribed_users[] = $row[0];
$db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN ('.implode(',', $topics).')') or error('Unable to delete subscriptions of merged topics', __FILE__, __LINE__, $db->error());
(See also ticket #599 where this code was introduced)