summaryrefslogtreecommitdiffstats
path: root/Bugzilla/WebService/Util.pm
diff options
context:
space:
mode:
authorSimon Green <sgreen@redhat.com>2013-07-26 01:57:44 +0200
committerSimon Green <sgreen@redhat.com>2013-07-26 01:57:44 +0200
commit74954fdd596cfc5c29d4e31310e584ffd4541313 (patch)
treea5c102ba591cf27fb82a3a0353e37f5c3a67667e /Bugzilla/WebService/Util.pm
parent8afeaf6dfbf490cb4e293945b7f12e3f5dcf236a (diff)
downloadbugzilla-74954fdd596cfc5c29d4e31310e584ffd4541313.tar.gz
bugzilla-74954fdd596cfc5c29d4e31310e584ffd4541313.tar.xz
Bug 880093 - Cache filter_wants
r=glob, a=glob
Diffstat (limited to 'Bugzilla/WebService/Util.pm')
-rw-r--r--Bugzilla/WebService/Util.pm24
1 files changed, 17 insertions, 7 deletions
diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm
index d2a8de85c..c24f95923 100644
--- a/Bugzilla/WebService/Util.pm
+++ b/Bugzilla/WebService/Util.pm
@@ -38,28 +38,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 {