From 2e44ee8fbe496a192099ba894df9dabd1b4fd6a7 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 11 Sep 2013 14:28:31 +0800 Subject: Bug 912564: tbpl gets deadlocks setting last_activity_ts --- extensions/UserProfile/bin/update.pl | 50 +++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'extensions/UserProfile/bin') diff --git a/extensions/UserProfile/bin/update.pl b/extensions/UserProfile/bin/update.pl index 4cdb08fe7..457585f8d 100755 --- a/extensions/UserProfile/bin/update.pl +++ b/extensions/UserProfile/bin/update.pl @@ -18,10 +18,45 @@ BEGIN { Bugzilla->extensions() } use Bugzilla::Constants; use Bugzilla::Extension::UserProfile::Util; +use Bugzilla::User; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); +my $dbh = Bugzilla->dbh; +my $user_ids; +my $verbose = grep { $_ eq '-v' } @ARGV; -my $user_ids = Bugzilla->dbh->selectcol_arrayref( +$user_ids = $dbh->selectcol_arrayref( + "SELECT user_id + FROM profiles_statistics_recalc + ORDER BY user_id", + { Slice => {} } +); + +if (@$user_ids) { + print "recalculating last_user_activity\n"; + my ($count, $total) = (0, scalar(@$user_ids)); + foreach my $user_id (@$user_ids) { + if ($verbose) { + $count++; + my $login = user_id_to_login($user_id); + print "$count/$total $login ($user_id)\n"; + } + $dbh->do( + "UPDATE profiles + SET last_activity_ts = ?, + last_statistics_ts = NULL + WHERE userid = ?", + undef, + last_user_activity($user_id), + $user_id + ); + } + $dbh->do( + "DELETE FROM profiles_statistics_recalc WHERE " . $dbh->sql_in('user_id', $user_ids) + ); +} + +$user_ids = $dbh->selectcol_arrayref( "SELECT userid FROM profiles WHERE last_activity_ts IS NOT NULL @@ -31,6 +66,15 @@ my $user_ids = Bugzilla->dbh->selectcol_arrayref( { Slice => {} } ); -foreach my $user_id (@$user_ids) { - update_statistics_by_user($user_id); +if (@$user_ids) { + $verbose && print "updating statistics\n"; + my ($count, $total) = (0, scalar(@$user_ids)); + foreach my $user_id (@$user_ids) { + if ($verbose) { + $count++; + my $login = user_id_to_login($user_id); + print "$count/$total $login ($user_id)\n"; + } + update_statistics_by_user($user_id); + } } -- cgit v1.2.3-24-g4f1b