From 290029c1c1ba8b3f1ef18b56c94f947bd550d056 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 24 Apr 2013 12:52:26 +0800 Subject: Bug 853483: Triage report times out on Firefox (Any) query --- extensions/BMO/lib/Reports/EmailQueue.pm | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 extensions/BMO/lib/Reports/EmailQueue.pm (limited to 'extensions/BMO/lib/Reports/EmailQueue.pm') diff --git a/extensions/BMO/lib/Reports/EmailQueue.pm b/extensions/BMO/lib/Reports/EmailQueue.pm new file mode 100644 index 000000000..1bf2ca003 --- /dev/null +++ b/extensions/BMO/lib/Reports/EmailQueue.pm @@ -0,0 +1,69 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::BMO::Reports::EmailQueue; +use strict; +use warnings; + +use Bugzilla::Error; +use Scalar::Util qw(blessed); +use Storable (); + +sub report { + my ($vars, $filter) = @_; + my $dbh = Bugzilla->dbh; + my $user = Bugzilla->user; + + $user->in_group('admin') || $user->in_group('infra') + || ThrowUserError('auth_failure', { group => 'admin', + action => 'run', + object => 'email_queue' }); + + my $query = " + SELECT j.jobid, + j.arg, + j.insert_time, + j.run_after AS run_time, + COUNT(e.jobid) AS error_count, + MAX(e.error_time) AS error_time, + e.message AS error_message + FROM ts_job j + LEFT JOIN ts_error e ON e.jobid = j.jobid + GROUP BY j.jobid + ORDER BY j.run_after"; + + $vars->{'jobs'} = $dbh->selectall_arrayref($query, { Slice => {} }); + foreach my $job (@{ $vars->{'jobs'} }) { + eval { + my $msg = _cond_thaw(delete $job->{'arg'})->{msg}; + if (ref($msg) && blessed($msg) eq 'Email::MIME') { + $job->{'subject'} = $msg->header('subject'); + } else { + ($job->{'subject'}) = $msg =~ /\nSubject: ([^\n]+)/; + } + }; + } + $vars->{'now'} = (time); +} + +sub _cond_thaw { + my $data = shift; + my $magic = eval { Storable::read_magic($data); }; + if ($magic && $magic->{major} && $magic->{major} >= 2 && $magic->{major} <= 5) { + my $thawed = eval { Storable::thaw($data) }; + if ($@) { + # false alarm... looked like a Storable, but wasn't. + return $data; + } + return $thawed; + } else { + return $data; + } +} + + +1; -- cgit v1.2.3-24-g4f1b