From: Frédéric Buclin Date: Fri, 27 Sep 2013 22:59:33 +0000 (+0200) Subject: Bug 340160: Speed up LogActivityEntry() X-Git-Tag: bugzilla-4.5.1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d802ebc16003e27fe86295ccd6b7c47996c7314;p=thirdparty%2Fbugzilla.git Bug 340160: Speed up LogActivityEntry() r=dkl a=justdave --- diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 4d2421a595..3000bd0aec 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -3953,7 +3953,11 @@ sub get_activity { # Update the bugs_activity table to reflect changes made in bugs. sub LogActivityEntry { my ($i, $col, $removed, $added, $whoid, $timestamp, $comment_id) = @_; - my $dbh = Bugzilla->dbh; + state $sth = + Bugzilla->dbh->prepare('INSERT INTO bugs_activity + (bug_id, who, bug_when, fieldid, removed, added, comment_id) + VALUES (?, ?, ?, ?, ?, ?, ?)'); + # in the case of CCs, deps, and keywords, there's a possibility that someone # might try to add or remove a lot of them at once, which might take more # space than the activity table allows. We'll solve this by splitting it @@ -3977,10 +3981,7 @@ sub LogActivityEntry { trick_taint($addstr); trick_taint($removestr); my $fieldid = get_field_id($col); - $dbh->do("INSERT INTO bugs_activity - (bug_id, who, bug_when, fieldid, removed, added, comment_id) - VALUES (?, ?, ?, ?, ?, ?, ?)", - undef, ($i, $whoid, $timestamp, $fieldid, $removestr, $addstr, $comment_id)); + $sth->execute($i, $whoid, $timestamp, $fieldid, $removestr, $addstr, $comment_id); } } diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index c4ee774987..ebc043ab77 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -1324,7 +1324,7 @@ sub check_field { Description: Returns the ID of the specified field name and throws an error if this field does not exist. -Params: $name - a field name +Params: $fieldname - a field name Returns: the corresponding field ID or an error if the field name does not exist. @@ -1334,15 +1334,10 @@ Returns: the corresponding field ID or an error if the field name =cut sub get_field_id { - my ($name) = @_; - my $dbh = Bugzilla->dbh; - - trick_taint($name); - my $id = $dbh->selectrow_array('SELECT id FROM fielddefs - WHERE name = ?', undef, $name); + my $field = Bugzilla->fields({ by_name => 1 })->{$_[0]} + or ThrowCodeError('invalid_field_name', {field => $_[0]}); - ThrowCodeError('invalid_field_name', {field => $name}) unless $id; - return $id + return $field->id; } 1;