From 5143d679ac939ae894f0799bea6db51ce6b023cb Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 21 May 2013 16:07:15 +0800 Subject: Bug 870202: investigate ways of improving the performance of bugmail composition --- Bugzilla/BugMail.pm | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'Bugzilla/BugMail.pm') diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index 37421ce3e..55a37c230 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -43,6 +43,7 @@ use Bugzilla::Bug; use Bugzilla::Comment; use Bugzilla::Mailer; use Bugzilla::Hook; +use Bugzilla::Instrument; use Date::Parse; use Date::Format; @@ -75,6 +76,16 @@ sub Send { my ($id, $forced, $params) = @_; $params ||= {}; + my $instrument; + my $current_login = Bugzilla->user->login; + if ($current_login eq 'ehsan@mozilla.com' + || $current_login eq 'glob@mozilla.com' + || $current_login eq 'dkl@mozilla.com') + { + $instrument = Bugzilla::Instrument->new('bugmail'); + $instrument->begin("bug $id user $current_login"); + } + my $dbh = Bugzilla->dbh; my $bug = new Bugzilla::Bug($id); @@ -155,6 +166,7 @@ sub Send { ########################################################################### # Start of email filtering code ########################################################################### + $instrument && $instrument->begin('email filtering'); # A user_id => roles hash to keep track of people. my %recipients; @@ -213,7 +225,9 @@ sub Send { Bugzilla::Hook::process('bugmail_recipients', { bug => $bug, recipients => \%recipients, users => \%user_cache, diffs => \@diffs }); + $instrument && $instrument->end(); + $instrument && $instrument->begin('watchers'); if (scalar keys %recipients) { # Find all those user-watching anyone on the current list, who is not # on it already themselves. @@ -240,6 +254,7 @@ sub Send { next unless $watcher_id; $recipients{$watcher_id}->{+REL_GLOBAL_WATCHER} = BIT_DIRECT; } + $instrument && $instrument->end(); # We now have a complete set of all the users, and their relationships to # the bug in question. However, we are not necessarily going to mail them @@ -327,6 +342,7 @@ sub Send { { updated_bug => $bug, referenced_bugs => $referenced_bugs }); + $instrument && $instrument->begin("sending to " . $user->login); $sent_mail = sendMail( { to => $user, bug => $bug, @@ -338,7 +354,9 @@ sub Send { diffs => \@diffs, rels_which_want => \%rels_which_want, referenced_bugs => $referenced_bugs, + instrument => $instrument, }); + $instrument && $instrument->end(); } } @@ -359,6 +377,7 @@ sub Send { $bug->{lastdiffed} = $end; } + $instrument && $instrument->end(); return {'sent' => \@sent, 'excluded' => \@excluded}; } @@ -374,6 +393,7 @@ sub sendMail { my @diffs = @{ $params->{diffs} }; my $relRef = $params->{rels_which_want}; my $referenced_bugs = $params->{referenced_bugs}; + my $instrument = $params->{instrument}; # Only display changes the user is allowed see. my @display_diffs; @@ -438,9 +458,14 @@ sub sendMail { new_comments => \@send_comments, threadingmarker => build_thread_marker($bug->id, $user->id, !$bug->lastdiffed), referenced_bugs => $referenced_bugs, + instrument => $instrument, }; + $instrument && $instrument->begin('generating bugmail'); my $msg = _generate_bugmail($user, $vars); + $instrument && $instrument->end(); + $instrument && $instrument->begin('sending to mta'); MessageToMTA($msg); + $instrument && $instrument->end(); return 1; } @@ -449,11 +474,17 @@ sub _generate_bugmail { my ($user, $vars) = @_; my $template = Bugzilla->template_inner($user->setting('lang')); my ($msg_text, $msg_html, $msg_header); - + my $instrument = $vars->{instrument}; + + $instrument && $instrument->begin('header'); $template->process("email/bugmail-header.txt.tmpl", $vars, \$msg_header) || ThrowTemplateError($template->error()); + $instrument && $instrument->end(); + + $instrument && $instrument->begin('text body'); $template->process("email/bugmail.txt.tmpl", $vars, \$msg_text) || ThrowTemplateError($template->error()); + $instrument && $instrument->end(); my @parts = ( Email::MIME->create( @@ -464,6 +495,7 @@ sub _generate_bugmail { ) ); if ($user->setting('email_format') eq 'html') { + $instrument && $instrument->begin('html body'); $template->process("email/bugmail.html.tmpl", $vars, \$msg_html) || ThrowTemplateError($template->error()); push @parts, Email::MIME->create( @@ -472,8 +504,10 @@ sub _generate_bugmail { }, body => $msg_html, ); + $instrument && $instrument->end(); } + $instrument && $instrument->begin('email object'); # TT trims the trailing newline, and threadingmarker may be ignored. my $email = new Email::MIME("$msg_header\n"); @@ -486,6 +520,7 @@ sub _generate_bugmail { $email->content_type_set('multipart/alternative'); } $email->parts_set(\@parts); + $instrument && $instrument->end(); return $email; } -- cgit v1.2.3-24-g4f1b