From 496cdc352852362e6c32a3e2ffbe0cd7cd409cda Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Tue, 9 May 2017 13:16:13 -0400 Subject: Bug 1362151 - Make /bzapi/configuration faster --- extensions/BzAPI/lib/Resources/Bugzilla.pm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'extensions/BzAPI') diff --git a/extensions/BzAPI/lib/Resources/Bugzilla.pm b/extensions/BzAPI/lib/Resources/Bugzilla.pm index f39cd29f3..a75a28864 100644 --- a/extensions/BzAPI/lib/Resources/Bugzilla.pm +++ b/extensions/BzAPI/lib/Resources/Bugzilla.pm @@ -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 { -- cgit v1.2.3-24-g4f1b