]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1501849 - Speed up IP blocked page: pre-render template
authorDylan William Hardison <dylan@hardison.net>
Fri, 26 Oct 2018 20:51:00 +0000 (16:51 -0400)
committerGitHub <noreply@github.com>
Fri, 26 Oct 2018 20:51:00 +0000 (16:51 -0400)
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)

.circleci/config.yml
Bugzilla/Quantum.pm
Bugzilla/Quantum/CGI.pm
Bugzilla/Quantum/Plugin/BlockIP.pm
Bugzilla/Template.pm

index 061ed9903367c4d279b710c94594271d62f70ded..7a203944e2f929c800c113a2e6ae1ebc7a8f694c 100644 (file)
@@ -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
index 84618a71b94859bc97998a5d893822403bacd6aa..e33e01d611d170cd2958509c5fe3cefc42c0a479 100644 (file)
@@ -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.
index 79fbcfde61ae9a34120d21c1ab53cc47cc324279..6a9492d06def30975492098014c157e692d87540 100644 (file)
@@ -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();
     };
   };
 
index c464fe49ec90a459c3c5319a26ede05b2c65ab15..56deb193576195d1dce2d7c641624044b79e71ce 100644 (file)
@@ -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;
   }
 }
 
index 9d2296cc8ccac27c46778a83e951297dff9b98ba..93101330b34c7a3f1df9ff9930f98670cbf21750 100644 (file)
@@ -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 {