From: Dylan William Hardison Date: Fri, 26 Oct 2018 20:51:00 +0000 (-0400) Subject: Bug 1501849 - Speed up IP blocked page: pre-render template X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e78468be65628b26cecae9500c0781e373fcf8b2;p=thirdparty%2Fbugzilla.git Bug 1501849 - Speed up IP blocked page: pre-render template By moving BlockIP plugin first, it is ensured to execute first. This is a slight speed gain. The primary speed gain is by caching the content of the template. Before: 429 Too Many Requests (0.031951s, 31.298/s) After: 429 Too Many Requests (0.000182s, 5494.505/s) --- diff --git a/.circleci/config.yml b/.circleci/config.yml index 061ed9903..7a203944e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,6 +62,9 @@ defaults: command: | [[ -f build_info/only_version_changed.txt ]] && exit 0 mv /opt/bmo/local /app/local + for file in patches/*.patch; do + patch -p0 < $file + done perl -MSys::Hostname -i -pE 's/bmo.test/hostname() . ":$ENV{PORT}"/ges' $BZ_QA_CONF_FILE perl checksetup.pl --no-database --default-localconfig mkdir artifacts diff --git a/Bugzilla/Quantum.pm b/Bugzilla/Quantum.pm index 84618a71b..e33e01d61 100644 --- a/Bugzilla/Quantum.pm +++ b/Bugzilla/Quantum.pm @@ -37,13 +37,13 @@ sub startup { my ($self) = @_; DEBUG('Starting up'); + $self->plugin('Bugzilla::Quantum::Plugin::BlockIP'); $self->plugin('Bugzilla::Quantum::Plugin::Glue'); $self->plugin('Bugzilla::Quantum::Plugin::Hostage') unless $ENV{BUGZILLA_DISABLE_HOSTAGE}; $self->plugin('Bugzilla::Quantum::Plugin::SizeLimit') unless $ENV{BUGZILLA_DISABLE_SIZELIMIT}; $self->plugin('ForwardedFor') if Bugzilla->has_feature('better_xff'); - $self->plugin('Bugzilla::Quantum::Plugin::BlockIP'); $self->plugin('Bugzilla::Quantum::Plugin::Helpers'); # hypnotoad is weird and doesn't look for MOJO_LISTEN itself. diff --git a/Bugzilla/Quantum/CGI.pm b/Bugzilla/Quantum/CGI.pm index 79fbcfde6..6a9492d06 100644 --- a/Bugzilla/Quantum/CGI.pm +++ b/Bugzilla/Quantum/CGI.pm @@ -61,6 +61,7 @@ sub load_one { $c->stash->{cleanup_guard}->dismiss; Bugzilla->usage_mode(USAGE_MODE_BROWSER); try { + CGI::initialize_globals(); Bugzilla->init_page(); $inner->(); } @@ -72,7 +73,6 @@ sub load_one { untie *STDOUT; $c->finish if !$error || _is_exit($error); Bugzilla->cleanup; - CGI::initialize_globals(); }; }; diff --git a/Bugzilla/Quantum/Plugin/BlockIP.pm b/Bugzilla/Quantum/Plugin/BlockIP.pm index c464fe49e..56deb1935 100644 --- a/Bugzilla/Quantum/Plugin/BlockIP.pm +++ b/Bugzilla/Quantum/Plugin/BlockIP.pm @@ -6,7 +6,8 @@ use Bugzilla::Memcached; use constant BLOCK_TIMEOUT => 60 * 60; -my $MEMCACHED = Bugzilla::Memcached->new()->{memcached}; +my $MEMCACHED = Bugzilla::Memcached->new()->{memcached}; +my $BLOCKED_HTML = ""; sub register { my ($self, $app, $conf) = @_; @@ -14,6 +15,13 @@ sub register { $app->hook(before_routes => \&_before_routes); $app->helper(block_ip => \&_block_ip); $app->helper(unblock_ip => \&_unblock_ip); + + my $template = Bugzilla::Template->create(); + $template->process('global/ip-blocked.html.tmpl', + {block_timeout => BLOCK_TIMEOUT}, + \$BLOCKED_HTML); + undef $template; + utf8::encode($BLOCKED_HTML); } sub _block_ip { @@ -35,7 +43,8 @@ sub _before_routes { $c->block_ip($ip); $c->res->code(429); $c->res->message('Too Many Requests'); - $c->render(handler => 'bugzilla', template => 'global/ip-blocked', block_timeout => BLOCK_TIMEOUT); + $c->write($BLOCKED_HTML); + $c->finish; } } diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 9d2296cc8..93101330b 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -49,7 +49,7 @@ use constant FORMAT_3_SIZE => [19,28,28]; use constant FORMAT_DOUBLE => '%19s %-55s'; use constant FORMAT_2_SIZE => [19,55]; -my %SHARED_PROVIDERS; +our %SHARED_PROVIDERS; # Pseudo-constant. sub SAFE_URL_REGEXP {