Commit bc14d441 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 341933: Make bug object creation much lighter

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=justdave
parent b0f0bf66
...@@ -100,10 +100,9 @@ sub _init { ...@@ -100,10 +100,9 @@ sub _init {
my $query = " my $query = "
SELECT SELECT
bugs.bug_id, alias, products.classification_id, classifications.name, bugs.bug_id, alias, bugs.product_id, version,
bugs.product_id, products.name, version,
rep_platform, op_sys, bug_status, resolution, priority, rep_platform, op_sys, bug_status, resolution, priority,
bug_severity, bugs.component_id, components.name, bug_severity, bugs.component_id,
assigned_to AS assigned_to_id, reporter AS reporter_id, assigned_to AS assigned_to_id, reporter AS reporter_id,
bug_file_loc, short_desc, target_milestone, bug_file_loc, short_desc, target_milestone,
qa_contact AS qa_contact_id, status_whiteboard, " . qa_contact AS qa_contact_id, status_whiteboard, " .
...@@ -112,14 +111,7 @@ sub _init { ...@@ -112,14 +111,7 @@ sub _init {
estimated_time, remaining_time, " . estimated_time, remaining_time, " .
$dbh->sql_date_format('deadline', '%Y-%m-%d') . $dbh->sql_date_format('deadline', '%Y-%m-%d') .
$custom_fields . " $custom_fields . "
FROM bugs FROM bugs WHERE bugs.bug_id = ?";
INNER JOIN components
ON components.id = bugs.component_id
INNER JOIN products
ON products.id = bugs.product_id
INNER JOIN classifications
ON classifications.id = products.classification_id
WHERE bugs.bug_id = ?";
my $bug_sth = $dbh->prepare($query); my $bug_sth = $dbh->prepare($query);
$bug_sth->execute($bug_id); $bug_sth->execute($bug_id);
...@@ -128,10 +120,9 @@ sub _init { ...@@ -128,10 +120,9 @@ sub _init {
if (@row = $bug_sth->fetchrow_array) { if (@row = $bug_sth->fetchrow_array) {
my $count = 0; my $count = 0;
my %fields; my %fields;
foreach my $field ("bug_id", "alias", "classification_id", "classification", foreach my $field ("bug_id", "alias", "product_id", "version",
"product_id", "product", "version",
"rep_platform", "op_sys", "bug_status", "resolution", "rep_platform", "op_sys", "bug_status", "resolution",
"priority", "bug_severity", "component_id", "component", "priority", "bug_severity", "component_id",
"assigned_to_id", "reporter_id", "assigned_to_id", "reporter_id",
"bug_file_loc", "short_desc", "bug_file_loc", "short_desc",
"target_milestone", "qa_contact_id", "status_whiteboard", "target_milestone", "qa_contact_id", "status_whiteboard",
...@@ -368,6 +359,36 @@ sub cc { ...@@ -368,6 +359,36 @@ sub cc {
return $self->{'cc'}; return $self->{'cc'};
} }
sub component {
my ($self) = @_;
return $self->{component} if exists $self->{component};
return '' if $self->{error};
($self->{component}) = Bugzilla->dbh->selectrow_array(
'SELECT name FROM components WHERE id = ?',
undef, $self->{component_id});
return $self->{component};
}
sub classification_id {
my ($self) = @_;
return $self->{classification_id} if exists $self->{classification_id};
return 0 if $self->{error};
($self->{classification_id}) = Bugzilla->dbh->selectrow_array(
'SELECT classification_id FROM products WHERE id = ?',
undef, $self->{product_id});
return $self->{classification_id};
}
sub classification {
my ($self) = @_;
return $self->{classification} if exists $self->{classification};
return '' if $self->{error};
($self->{classification}) = Bugzilla->dbh->selectrow_array(
'SELECT name FROM classifications WHERE id = ?',
undef, $self->classification_id);
return $self->{classification};
}
sub dependson { sub dependson {
my ($self) = @_; my ($self) = @_;
return $self->{'dependson'} if exists $self->{'dependson'}; return $self->{'dependson'} if exists $self->{'dependson'};
...@@ -432,11 +453,21 @@ sub milestoneurl { ...@@ -432,11 +453,21 @@ sub milestoneurl {
return $self->{'milestoneurl'} if exists $self->{'milestoneurl'}; return $self->{'milestoneurl'} if exists $self->{'milestoneurl'};
return '' if $self->{'error'}; return '' if $self->{'error'};
$self->{'prod_obj'} ||= new Bugzilla::Product({name => $self->{'product'}}); $self->{'prod_obj'} ||= new Bugzilla::Product({name => $self->product});
$self->{'milestoneurl'} = $self->{'prod_obj'}->milestone_url; $self->{'milestoneurl'} = $self->{'prod_obj'}->milestone_url;
return $self->{'milestoneurl'}; return $self->{'milestoneurl'};
} }
sub product {
my ($self) = @_;
return $self->{product} if exists $self->{product};
return '' if $self->{error};
($self->{product}) = Bugzilla->dbh->selectrow_array(
'SELECT name FROM products WHERE id = ?',
undef, $self->{product_id});
return $self->{product};
}
sub qa_contact { sub qa_contact {
my ($self) = @_; my ($self) = @_;
return $self->{'qa_contact'} if exists $self->{'qa_contact'}; return $self->{'qa_contact'} if exists $self->{'qa_contact'};
...@@ -490,7 +521,7 @@ sub use_votes { ...@@ -490,7 +521,7 @@ sub use_votes {
my ($self) = @_; my ($self) = @_;
return 0 if $self->{'error'}; return 0 if $self->{'error'};
$self->{'prod_obj'} ||= new Bugzilla::Product({name => $self->{'product'}}); $self->{'prod_obj'} ||= new Bugzilla::Product({name => $self->product});
return Bugzilla->params->{'usevotes'} return Bugzilla->params->{'usevotes'}
&& $self->{'prod_obj'}->votes_per_user > 0; && $self->{'prod_obj'}->votes_per_user > 0;
...@@ -601,13 +632,13 @@ sub choices { ...@@ -601,13 +632,13 @@ sub choices {
return {} if $self->{'error'}; return {} if $self->{'error'};
$self->{'choices'} = {}; $self->{'choices'} = {};
$self->{prod_obj} ||= new Bugzilla::Product({name => $self->{product}}); $self->{prod_obj} ||= new Bugzilla::Product({name => $self->product});
my @prodlist = map {$_->name} @{Bugzilla->user->get_enterable_products}; my @prodlist = map {$_->name} @{Bugzilla->user->get_enterable_products};
# The current product is part of the popup, even if new bugs are no longer # The current product is part of the popup, even if new bugs are no longer
# allowed for that product # allowed for that product
if (lsearch(\@prodlist, $self->{'product'}) < 0) { if (lsearch(\@prodlist, $self->product) < 0) {
push(@prodlist, $self->{'product'}); push(@prodlist, $self->product);
@prodlist = sort @prodlist; @prodlist = sort @prodlist;
} }
......
...@@ -346,7 +346,7 @@ foreach my $field (@enter_bug_fields) { ...@@ -346,7 +346,7 @@ foreach my $field (@enter_bug_fields) {
if ($cloned_bug_id) { if ($cloned_bug_id) {
$default{'component_'} = $cloned_bug->{'component'}; $default{'component_'} = $cloned_bug->component;
$default{'priority'} = $cloned_bug->{'priority'}; $default{'priority'} = $cloned_bug->{'priority'};
$default{'bug_severity'} = $cloned_bug->{'bug_severity'}; $default{'bug_severity'} = $cloned_bug->{'bug_severity'};
$default{'rep_platform'} = $cloned_bug->{'rep_platform'}; $default{'rep_platform'} = $cloned_bug->{'rep_platform'};
...@@ -431,7 +431,7 @@ else { ...@@ -431,7 +431,7 @@ else {
$vars->{'version'} = [map($_->name, @{$product->versions})]; $vars->{'version'} = [map($_->name, @{$product->versions})];
if ( ($cloned_bug_id) && if ( ($cloned_bug_id) &&
($product->name eq $cloned_bug->{'product'} ) ) { ($product->name eq $cloned_bug->product ) ) {
$default{'version'} = $cloned_bug->{'version'}; $default{'version'} = $cloned_bug->{'version'};
} elsif (formvalue('version')) { } elsif (formvalue('version')) {
$default{'version'} = formvalue('version'); $default{'version'} = formvalue('version');
...@@ -518,7 +518,7 @@ foreach my $row (@$grouplist) { ...@@ -518,7 +518,7 @@ foreach my $row (@$grouplist) {
# set a groups's checkbox based on the group control map # set a groups's checkbox based on the group control map
# #
if ( ($cloned_bug_id) && if ( ($cloned_bug_id) &&
($product->name eq $cloned_bug->{'product'} ) ) { ($product->name eq $cloned_bug->product ) ) {
foreach my $i (0..(@{$cloned_bug->{'groups'}}-1) ) { foreach my $i (0..(@{$cloned_bug->{'groups'}}-1) ) {
if ($cloned_bug->{'groups'}->[$i]->{'bit'} == $id) { if ($cloned_bug->{'groups'}->[$i]->{'bit'} == $id) {
$check = $cloned_bug->{'groups'}->[$i]->{'ison'}; $check = $cloned_bug->{'groups'}->[$i]->{'ison'};
......
...@@ -267,7 +267,7 @@ sub record_votes { ...@@ -267,7 +267,7 @@ sub record_votes {
# XXX - We really need a $bug->product() method. # XXX - We really need a $bug->product() method.
foreach my $bug_id (@buglist) { foreach my $bug_id (@buglist) {
my $bug = new Bugzilla::Bug($bug_id); my $bug = new Bugzilla::Bug($bug_id);
my $prod = $bug->{'product'}; my $prod = $bug->product;
$products{$prod} ||= new Bugzilla::Product({name => $prod}); $products{$prod} ||= new Bugzilla::Product({name => $prod});
$prodcount{$prod} ||= 0; $prodcount{$prod} ||= 0;
$prodcount{$prod} += $votes{$bug_id}; $prodcount{$prod} += $votes{$bug_id};
......
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