]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 341933: Make bug object creation much lighter
authormkanat%bugzilla.org <>
Thu, 17 Aug 2006 04:23:15 +0000 (04:23 +0000)
committermkanat%bugzilla.org <>
Thu, 17 Aug 2006 04:23:15 +0000 (04:23 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=justdave

Bugzilla/Bug.pm
enter_bug.cgi
votes.cgi

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