]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 749540: Avoid database deadlocks when deleting recent searches
authorByron Jones <bjones@mozilla.com>
Wed, 5 Sep 2012 07:09:55 +0000 (15:09 +0800)
committerByron Jones <bjones@mozilla.com>
Wed, 5 Sep 2012 07:09:55 +0000 (15:09 +0800)
r=dkl, a=LpSolit

Bugzilla/Search/Recent.pm

index 02c3ec37a5f920199d7f88b588ccb7bfb2333bb9..1ff56c7e357b3c8376f94b987e4c19ca85b65f66 100644 (file)
@@ -51,12 +51,13 @@ sub create {
     my $user_id = $search->user_id;
 
     # Enforce there only being SAVE_NUM_SEARCHES per user.
-    my $min_id = $dbh->selectrow_array(
-        'SELECT id FROM profile_search WHERE user_id = ? ORDER BY id DESC '
-        . $dbh->sql_limit(1, SAVE_NUM_SEARCHES), undef, $user_id);
-    if ($min_id) {
-        $dbh->do('DELETE FROM profile_search WHERE user_id = ? AND id <= ?',
-                 undef, ($user_id, $min_id));
+    my @ids = @{ $dbh->selectcol_arrayref(
+        "SELECT id FROM profile_search WHERE user_id = ? ORDER BY id",
+        undef, $user_id) };
+    if (scalar(@ids) > SAVE_NUM_SEARCHES) {
+        splice(@ids, - SAVE_NUM_SEARCHES);
+        $dbh->do(
+            "DELETE FROM profile_search WHERE id IN (" . join(',', @ids) . ")");
     }
     $dbh->bz_commit_transaction();
     return $search;