aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2012-09-05 15:08:56 +0800
committerByron Jones <bjones@mozilla.com>2012-09-05 15:08:56 +0800
commit9b274039cdb9182dffc3866184d9b530f8fb8859 (patch)
tree934419944779f904d4eda4ffec798c66d3808231
parentbcbdb84677b662d2172a0a1ec4d206bd4f694c51 (diff)
downloadbugs-9b274039cdb9182dffc3866184d9b530f8fb8859.tar
bugs-9b274039cdb9182dffc3866184d9b530f8fb8859.tar.gz
bugs-9b274039cdb9182dffc3866184d9b530f8fb8859.tar.bz2
bugs-9b274039cdb9182dffc3866184d9b530f8fb8859.tar.xz
bugs-9b274039cdb9182dffc3866184d9b530f8fb8859.zip
Bug 749540: Avoid database deadlocks when deleting recent searches
r=dkl, a=LpSolit
-rw-r--r--Bugzilla/Search/Recent.pm13
1 files changed, 7 insertions, 6 deletions
diff --git a/Bugzilla/Search/Recent.pm b/Bugzilla/Search/Recent.pm
index 00b71a91d..f1dd092b2 100644
--- a/Bugzilla/Search/Recent.pm
+++ b/Bugzilla/Search/Recent.pm
@@ -54,12 +54,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;