]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1501849 - Speed up IP blocked page: cache params in memcached
authorDylan William Hardison <dylan@hardison.net>
Mon, 26 Nov 2018 21:04:53 +0000 (16:04 -0500)
committerGitHub <noreply@github.com>
Mon, 26 Nov 2018 21:04:53 +0000 (16:04 -0500)
Bugzilla/Config.pm
Bugzilla/Install/Localconfig.pm
Bugzilla/Memcached.pm

index 1016d51e43d44d368ea27fc54323dda9e0027aa5..db578aaabf3cfc0f661f63f92b4449e0cc57e5d2 100644 (file)
@@ -260,10 +260,13 @@ sub write_params {
 
     # And now we have to reset the params cache so that Bugzilla will re-read
     # them.
+    Bugzilla->memcached->clear_params();
     delete Bugzilla->request_cache->{params};
 }
 
 sub read_param_file {
+    my $cached_params = Bugzilla->memcached->get_params();
+    return $cached_params if $cached_params;
     my %params;
     my $datadir = bz_locations()->{'datadir'};
     if (-e "$datadir/params") {
@@ -292,6 +295,7 @@ sub read_param_file {
        die "The $datadir/params file does not exist."
            . ' You probably need to run checksetup.pl.',
     }
+    Bugzilla->memcached->set_params(\%params);
     return \%params;
 }
 
index 4b25b966bdeab3552a8f85d109bd3ea418c58425..b883dde807c3a5011b88c7c92b625463f8e3daa7 100644 (file)
@@ -51,19 +51,6 @@ sub _sensible_group {
     return scalar getgrgid($EGID);
 }
 
-sub _migrate_param {
-    my ( $name, $fallback_value ) = @_;
-
-    return sub {
-        if ( Bugzilla->can('params') ) {
-            return Bugzilla->params->{$name} // $fallback_value;
-        }
-        else {
-            return $fallback_value;
-        }
-    };
-}
-
 use constant LOCALCONFIG_VARS => (
     {
         name    => 'create_htaccess',
@@ -158,15 +145,15 @@ use constant LOCALCONFIG_VARS => (
     },
     {
         name    => 'memcached_servers',
-        default => _migrate_param( "memcached_servers", "" ),
+        default => '',
     },
     {
         name    => 'memcached_namespace',
-        default => _migrate_param( "memcached_namespace", "bugzilla:" ),
+        default => "bugzilla:",
     },
     {
         name    => 'urlbase',
-        default => _migrate_param( "urlbase", "" ),
+        default => '',
     },
     {
         name    => 'canonical_urlbase',
@@ -174,7 +161,7 @@ use constant LOCALCONFIG_VARS => (
     },
     {
         name    => 'attachment_base',
-        default => _migrate_param( "attachment_base", '' ),
+        default => '',
     },
     {
         name    => 'ses_username',
@@ -186,7 +173,7 @@ use constant LOCALCONFIG_VARS => (
     },
     {
         name => 'inbound_proxies',
-        default => _migrate_param( 'inbound_proxies', '' ),
+        default => '',
     },
     {
         name => 'shadowdb_user',
index 6bbef080a757a5422c33b4b8a90daa85bb64b522..815b300d4da55078a968d95ba0b9154d2e01d893 100644 (file)
@@ -156,6 +156,26 @@ sub get_config {
     }
 }
 
+sub set_params {
+    my ($self, $params) = @_;
+    return unless $self->{memcached};
+
+    return $self->_set($self->_params_prefix . ".params", $params);
+}
+
+sub get_params {
+    my ($self) = @_;
+    return unless $self->{memcached};
+
+    return $self->_get($self->_params_prefix . ".params");
+}
+
+sub clear_params {
+    my ($self, $args) = @_;
+    return unless $self->{memcached};
+    $self->_inc_prefix("params");
+}
+
 sub set_bloomfilter {
     my ($self, $args) = @_;
     return unless $self->{memcached};
@@ -270,6 +290,7 @@ sub clear_config {
 sub _prefix {
     my ($self, $name) = @_;
     # we don't want to change prefixes in the middle of a request
+    $name .= "/" . Bugzilla->VERSION;
     my $request_cache = Bugzilla->request_cache;
     my $request_cache_key = "memcached_prefix_$name";
     if (!$request_cache->{$request_cache_key}) {
@@ -293,6 +314,7 @@ sub _prefix {
 sub _inc_prefix {
     my ($self, $name) = @_;
     my $memcached = $self->{memcached};
+    $name .= "/" . Bugzilla->VERSION;
     if (!$memcached->incr($name, 1)) {
         $memcached->add($name, time());
     }
@@ -310,6 +332,10 @@ sub _config_prefix {
     return $_[0]->_prefix("config");
 }
 
+sub _params_prefix {
+    return $_[0]->_prefix("params");
+}
+
 sub _bloomfilter_prefix {
     return $_[0]->_prefix("bloomfilter");
 }