From: Dylan William Hardison Date: Mon, 26 Nov 2018 21:04:53 +0000 (-0500) Subject: Bug 1501849 - Speed up IP blocked page: cache params in memcached X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f8f6d2bf1a6b64b404c85ec62acbbf3a90690d5;p=thirdparty%2Fbugzilla.git Bug 1501849 - Speed up IP blocked page: cache params in memcached --- diff --git a/Bugzilla/Config.pm b/Bugzilla/Config.pm index 1016d51e4..db578aaab 100644 --- a/Bugzilla/Config.pm +++ b/Bugzilla/Config.pm @@ -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; } diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm index 4b25b966b..b883dde80 100644 --- a/Bugzilla/Install/Localconfig.pm +++ b/Bugzilla/Install/Localconfig.pm @@ -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', diff --git a/Bugzilla/Memcached.pm b/Bugzilla/Memcached.pm index 6bbef080a..815b300d4 100644 --- a/Bugzilla/Memcached.pm +++ b/Bugzilla/Memcached.pm @@ -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"); }