From: Dylan William Hardison Date: Tue, 29 Jan 2019 21:57:11 +0000 (-0500) Subject: Bug 1512815 - Make Bugzilla->active_custom_wants() 10x faster when using specific... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c55e2ec531e3092e4e6b1945cac9d70bd012b9b;p=thirdparty%2Fbugzilla.git Bug 1512815 - Make Bugzilla->active_custom_wants() 10x faster when using specific include_fields --- diff --git a/Bugzilla.pm b/Bugzilla.pm index 21177e3fd..38fed5ac0 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -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 { diff --git a/Bugzilla/WebService.pm b/Bugzilla/WebService.pm index eb6db2081..4a0264f9c 100644 --- a/Bugzilla/WebService.pm +++ b/Bugzilla/WebService.pm @@ -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; diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index ab7bb3572..9f00675f1 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -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']); diff --git a/extensions/TrackingFlags/Extension.pm b/extensions/TrackingFlags/Extension.pm index 5879a5e55..22c07f955 100644 --- a/extensions/TrackingFlags/Extension.pm +++ b/extensions/TrackingFlags/Extension.pm @@ -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;