Commit 02024e93 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 713144: The SQL query to remove older searches from the profile_search table…

Bug 713144: The SQL query to remove older searches from the profile_search table should be more robust r=dkl a=LpSolit
parent 37e65a3c
...@@ -57,14 +57,16 @@ sub create { ...@@ -57,14 +57,16 @@ sub create {
my $class = shift; my $class = shift;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
$dbh->bz_start_transaction(); $dbh->bz_start_transaction();
my $search = $class->SUPER::create(@_); my $search = $class->SUPER::create(@_);
my $user_id = $search->user_id;
# Enforce there only being SAVE_NUM_SEARCHES per user. # Enforce there only being SAVE_NUM_SEARCHES per user.
my ($num_searches, $min_id) = $dbh->selectrow_array( my $min_id = $dbh->selectrow_array(
'SELECT COUNT(*), MIN(id) FROM profile_search WHERE user_id = ?', 'SELECT id FROM profile_search WHERE user_id = ? ORDER BY id DESC '
undef, $search->user_id); . $dbh->sql_limit(1, SAVE_NUM_SEARCHES), undef, $user_id);
if ($num_searches > SAVE_NUM_SEARCHES) { if ($min_id) {
$dbh->do('DELETE FROM profile_search WHERE id = ?', undef, $min_id); $dbh->do('DELETE FROM profile_search WHERE user_id = ? AND id <= ?',
undef, ($user_id, $min_id));
} }
$dbh->bz_commit_transaction(); $dbh->bz_commit_transaction();
return $search; return $search;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment