]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 880093 - Cache filter_wants
authorSimon Green <sgreen@redhat.com>
Thu, 25 Jul 2013 23:57:44 +0000 (09:57 +1000)
committerSimon Green <sgreen@redhat.com>
Thu, 25 Jul 2013 23:57:44 +0000 (09:57 +1000)
r=glob, a=glob

Bugzilla/WebService/Util.pm

index d2a8de85c12ac4ee78e9ad9c3001356f26895e96..c24f95923dcc44eb39b2886b294ab6bf45b0583a 100644 (file)
@@ -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 {