From cfab86c4b4201382fc54c5ed0f85e852f284f9a3 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sat, 17 Mar 2018 10:30:09 +0100 Subject: [PATCH] Move some tasks to recurring instead of being in after_dispatch hook --- CHANGELOG | 1 + lib/Lutim.pm | 19 ++++++++++--------- themes/default/lib/Lutim/I18N/lutim.pot | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 81a71c0..4fd8a5a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Revision history for Lutim ????? ?????????? - PostgreSQL performance improvments + - Move some tasks to recurring instead of being in after_dispatch hook 0.9.6 2018-03-12 - Update translations diff --git a/lib/Lutim.pm b/lib/Lutim.pm index ab58ba0..b8cd1cc 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -1,6 +1,7 @@ # vim:set sw=4 ts=4 sts=4 ft=perl expandtab: package Lutim; use Mojo::Base 'Mojolicious'; +use Mojo::IOLoop; use Lutim::DB::Image; use vars qw($im_loaded); @@ -131,16 +132,16 @@ sub startup { } ); - $self->hook( - after_dispatch => sub { - my $c = shift; - $c->provisioning(); + # Recurrent tasks + Mojo::IOLoop->recurring(5 => sub { + my $loop = shift; - # Purge expired anti-flood protection - my $wait_for_it = $c->app->{wait_for_it}; - delete @{$wait_for_it}{grep { time - $wait_for_it->{$_} > $c->config->{anti_flood_delay} } keys %{$wait_for_it}} if (defined($wait_for_it)); - } - ); + $self->provisioning(); + + # Purge expired anti-flood protection + my $wait_for_it = $self->{wait_for_it}; + delete @{$wait_for_it}{grep { time - $wait_for_it->{$_} > $self->config->{anti_flood_delay} } keys %{$wait_for_it}} if (defined($wait_for_it)); + }); $self->defaults(layout => 'default'); diff --git a/themes/default/lib/Lutim/I18N/lutim.pot b/themes/default/lib/Lutim/I18N/lutim.pot index 9842998..acd6efd 100644 --- a/themes/default/lib/Lutim/I18N/lutim.pot +++ b/themes/default/lib/Lutim/I18N/lutim.pot @@ -32,11 +32,11 @@ msgstr "" msgid "-or-" msgstr "" -#: lib/Lutim.pm:187 lib/Lutim/Command/cron/stats.pm:151 lib/Lutim/Command/cron/stats.pm:162 lib/Lutim/Command/cron/stats.pm:179 themes/default/templates/index.html.ep:5 themes/default/templates/raw.html.ep:10 themes/default/templates/raw.html.ep:21 themes/default/templates/raw.html.ep:38 +#: lib/Lutim.pm:188 lib/Lutim/Command/cron/stats.pm:151 lib/Lutim/Command/cron/stats.pm:162 lib/Lutim/Command/cron/stats.pm:179 themes/default/templates/index.html.ep:5 themes/default/templates/raw.html.ep:10 themes/default/templates/raw.html.ep:21 themes/default/templates/raw.html.ep:38 msgid "1 year" msgstr "" -#: lib/Lutim.pm:186 lib/Lutim/Command/cron/stats.pm:148 lib/Lutim/Command/cron/stats.pm:159 lib/Lutim/Command/cron/stats.pm:176 themes/default/templates/index.html.ep:4 themes/default/templates/partial/for_my_delay.html.ep:13 themes/default/templates/partial/lutim.js.ep:151 themes/default/templates/raw.html.ep:18 themes/default/templates/raw.html.ep:35 themes/default/templates/raw.html.ep:7 +#: lib/Lutim.pm:187 lib/Lutim/Command/cron/stats.pm:148 lib/Lutim/Command/cron/stats.pm:159 lib/Lutim/Command/cron/stats.pm:176 themes/default/templates/index.html.ep:4 themes/default/templates/partial/for_my_delay.html.ep:13 themes/default/templates/partial/lutim.js.ep:151 themes/default/templates/raw.html.ep:18 themes/default/templates/raw.html.ep:35 themes/default/templates/raw.html.ep:7 msgid "24 hours" msgstr "" @@ -495,7 +495,7 @@ msgstr "" msgid "core developer" msgstr "" -#: lib/Lutim.pm:185 lib/Lutim/Command/cron/stats.pm:147 lib/Lutim/Command/cron/stats.pm:158 lib/Lutim/Command/cron/stats.pm:175 themes/default/templates/index.html.ep:3 themes/default/templates/raw.html.ep:17 themes/default/templates/raw.html.ep:34 themes/default/templates/raw.html.ep:6 +#: lib/Lutim.pm:186 lib/Lutim/Command/cron/stats.pm:147 lib/Lutim/Command/cron/stats.pm:158 lib/Lutim/Command/cron/stats.pm:175 themes/default/templates/index.html.ep:3 themes/default/templates/raw.html.ep:17 themes/default/templates/raw.html.ep:34 themes/default/templates/raw.html.ep:6 msgid "no time limit" msgstr ""