]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1362151 - Make /bzapi/configuration faster
authorDylan William Hardison <dylan@hardison.net>
Tue, 9 May 2017 17:16:13 +0000 (13:16 -0400)
committerDylan William Hardison <dylan@hardison.net>
Tue, 9 May 2017 17:16:13 +0000 (13:16 -0400)
Bugzilla/Memcached.pm
extensions/BzAPI/lib/Resources/Bugzilla.pm

index 6ada1adf8ec68a59acc927184a0bd9542edeb74c..e8c17876d3015671882ed340d725d70862b1df46 100644 (file)
@@ -36,6 +36,7 @@ sub _new {
         $self->{memcached} = Cache::Memcached::Fast->new({
             servers   => [ split(/[, ]+/, $servers) ],
             namespace => $self->{namespace},
+            max_size => 1024 * 1024 * 2,
         });
     }
     return bless($self, $class);
index f39cd29f31c5bf612b3c45ab15f1f37a4330306c..a75a2886414f8400b06b31a636d180ddf7ad139b 100644 (file)
@@ -59,6 +59,14 @@ sub get_configuration {
     my $user   = Bugzilla->user;
     my $params = Bugzilla->input_params;
 
+    my $can_cache = not exists $params->{product} and not exists $params->{flags};
+    my $cache_key = 'bzapi_get_configuration';
+
+    if ($can_cache) {
+        my $result = Bugzilla->memcached->get_config({key => $cache_key});
+        return $result if defined $result;
+    }
+
     # Get data from the shadow DB as they don't change very often.
     Bugzilla->switch_to_shadow_db;
 
@@ -120,11 +128,16 @@ sub get_configuration {
 
     my $json;
     Bugzilla->template->process('config.json.tmpl', $vars, \$json);
-    my $result = {};
     if ($json) {
-        $result = $self->json->decode($json);
+        my $result = $self->json->decode($json);
+        if ($can_cache) {
+            Bugzilla->memcached->set_config({key => $cache_key, data => $result});
+        }
+        return $result;
+    }
+    else {
+        return {};
     }
-    return $result;
 }
 
 sub get_empty {