]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1512815 - Make Bugzilla->active_custom_wants() 10x faster when using specific...
authorDylan William Hardison <dylan@hardison.net>
Tue, 29 Jan 2019 21:57:11 +0000 (16:57 -0500)
committerGitHub <noreply@github.com>
Tue, 29 Jan 2019 21:57:11 +0000 (16:57 -0500)
Bugzilla.pm
Bugzilla/WebService.pm
Bugzilla/WebService/Bug.pm
extensions/TrackingFlags/Extension.pm

index 21177e3fd88d2a2b0580c930e0c336e7432988c2..38fed5ac0dff4108fec67e04a7e43775a652f288 100644 (file)
@@ -676,27 +676,36 @@ sub fields {
 }
 
 sub active_custom_fields {
-  my (undef, $params) = @_;
-  my $cache_id  = 'active_custom_fields';
-  my $can_cache = !exists $params->{bug_id};
-  if ($params) {
+  my (undef, $params, $wants) = @_;
+  my $cache_id = 'active_custom_fields';
+  my $can_cache = !exists $params->{bug_id} && !$wants;
+  if ($can_cache && $params) {
     $cache_id .= ($params->{product} ? '_p' . $params->{product}->id : '')
       . ($params->{component} ? '_c' . $params->{component}->id : '');
     $cache_id .= ':noext' if $params->{skip_extensions};
   }
-  if (!$can_cache || !exists request_cache->{$cache_id}) {
-    my $fields
-      = Bugzilla::Field->match({custom => 1, obsolete => 0, skip_extensions => 1});
-    Bugzilla::Hook::process('active_custom_fields',
-      {fields => \$fields, params => $params});
-    if ($can_cache) {
-      request_cache->{$cache_id} = $fields;
-    }
-    else {
-      return @$fields;
+
+  if ($can_cache && exists request_cache->{$cache_id}) {
+    return @{request_cache->{$cache_id}};
+  }
+  else {
+    my $match_params = {custom => 1, obsolete => 0, skip_extensions => 1};
+    if ($wants) {
+      if ($wants->exclude->{custom}) {
+        return ();
+      }
+      elsif ($wants->is_specific) {
+        my @names = (grep {/^cf_/} $wants->includes);
+        return () unless @names;
+        $match_params->{name} = \@names;
+      }
     }
+    my $fields = Bugzilla::Field->match($match_params);
+    Bugzilla::Hook::process('active_custom_fields',
+      {fields => \$fields, params => $params, wants => $wants});
+    request_cache->{$cache_id} = $fields if $can_cache;
+    return @$fields;
   }
-  return @{request_cache->{$cache_id}};
 }
 
 sub has_flags {
index eb6db20816f6d329802d26cf64136c44b28cec4e..4a0264f9cefca6b900e0096e1bcc2a3ecbea94e2 100644 (file)
@@ -40,15 +40,17 @@ sub login_exempt {
 }
 
 sub wants_object {
-  my ($self) = @_;
-  return $self->{__wants_object} if $self->{__wants_object};
-  my $params = Bugzilla->input_params;
-  my $wants  = Bugzilla::WebService::Wants->new(
-    cache                => Bugzilla->request_cache->{filter_wants} ||= {},
-    maybe include_fields => $params->{include_fields},
-    maybe exclude_fields => $params->{exclude_fields},
-  );
-  return $self->{__wants_object} = $wants;
+  my ($class) = @_;
+  my $cache = Bugzilla->request_cache;
+
+  return $cache->{filter_wants_object} //= do {
+    my $params = Bugzilla->input_params;
+     Bugzilla::WebService::Wants->new(
+      cache                => $cache->{filter_wants} ||= {},
+      maybe include_fields => $params->{include_fields},
+      maybe exclude_fields => $params->{exclude_fields},
+    );
+  };
 }
 
 1;
index ab7bb3572faf33619f940afbaae7c691119a2e49..9f00675f181bdb52101a7030925ba87499f31c42 100644 (file)
@@ -1523,11 +1523,14 @@ sub _bug_to_hash {
   }
 
   # And now custom fields
-  my @custom_fields = Bugzilla->active_custom_fields({
-    product   => $bug->product_obj,
-    component => $bug->component_obj,
-    bug_id    => $bug->id
-  });
+  my @custom_fields = Bugzilla->active_custom_fields(
+    {
+      product   => $bug->product_obj,
+      component => $bug->component_obj,
+      bug_id    => $bug->id
+    },
+    $self->wants_object,
+  );
   foreach my $field (@custom_fields) {
     my $name = $field->name;
     next if !filter_wants($params, $name, ['default', 'custom']);
index 5879a5e55ac10355d0860d305982c64703869760..22c07f955dad06f28c9780bfd6dc46c6d0b010ea 100644 (file)
@@ -301,12 +301,16 @@ sub install_filesystem {
 
 sub active_custom_fields {
   my ($self, $args) = @_;
+  my $wants     = $args->{'wants'};
   my $fields    = $args->{'fields'};
   my $params    = $args->{'params'};
   my $product   = $params->{'product'};
   my $component = $params->{'component'};
 
   return if $params->{skip_extensions};
+  if ($wants && $wants->is_specific) {
+    return if none { $wants->include->{$_} } Bugzilla->tracking_flag_names;
+  }
 
   # Create a hash of current fields based on field names
   my %field_hash = map { $_->name => $_ } @$$fields;