diff options
author | Simon Green <sgreen@redhat.com> | 2013-07-26 09:58:19 +1000 |
---|---|---|
committer | Simon Green <sgreen@redhat.com> | 2013-07-26 09:58:19 +1000 |
commit | 9e5b0eae4d6cad269a0674089915cbb5044d6e8b (patch) | |
tree | 5bd36f83a216c2ec10a4f491237aa6e7b5238453 | |
parent | Bug 889403: syncLDAP.pl does not rederive regexp groups when updating login name (diff) | |
download | bugzilla-9e5b0eae4d6cad269a0674089915cbb5044d6e8b.tar.gz bugzilla-9e5b0eae4d6cad269a0674089915cbb5044d6e8b.tar.bz2 bugzilla-9e5b0eae4d6cad269a0674089915cbb5044d6e8b.zip |
Bug 880093 - Cache filter_wants
r=glob, a=glob
-rw-r--r-- | Bugzilla/WebService/Util.pm | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm index 12606fb70..6e935fe20 100644 --- a/Bugzilla/WebService/Util.pm +++ b/Bugzilla/WebService/Util.pm @@ -35,28 +35,38 @@ sub filter ($$;$) { sub filter_wants ($$;$) { my ($params, $field, $prefix) = @_; - my %include = map { $_ => 1 } @{ $params->{'include_fields'} || [] }; - my %exclude = map { $_ => 1 } @{ $params->{'exclude_fields'} || [] }; + # Since this is operation is resource intensive, we will cache the results + # This assumes that $params->{*_fields} doesn't change between calls + my $cache = Bugzilla->request_cache->{filter_wants} ||= {}; $field = "${prefix}.${field}" if $prefix; + if (exists $cache->{$field}) { + return $cache->{$field}; + } + + my %include = map { $_ => 1 } @{ $params->{'include_fields'} || [] }; + my %exclude = map { $_ => 1 } @{ $params->{'exclude_fields'} || [] }; + + my $wants = 1; if (defined $params->{exclude_fields} && $exclude{$field}) { - return 0; + $wants = 0; } - if (defined $params->{include_fields} && !$include{$field}) { + elsif (defined $params->{include_fields} && !$include{$field}) { if ($prefix) { # Include the field if the parent is include (and this one is not excluded) - return 0 if !$include{$prefix}; + $wants = 0 if !$include{$prefix}; } else { # We want to include this if one of the sub keys is included my $key = $field . '.'; my $len = length($key); - return 0 if ! grep { substr($_, 0, $len) eq $key } keys %include; + $wants = 0 if ! grep { substr($_, 0, $len) eq $key } keys %include; } } - return 1; + $cache->{$field} = $wants; + return $wants; } sub taint_data { |