From a5ab4fa6a8a41c2fd50cfa2ad8bee1c985ffd593 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 3 Dec 2020 21:42:17 +0100 Subject: regularly generate statistics in the background --- lib/Travelynx/Command/maintenance.pm | 17 +++++++++++++++++ lib/Travelynx/Command/work.pm | 13 ------------- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'lib/Travelynx/Command') diff --git a/lib/Travelynx/Command/maintenance.pm b/lib/Travelynx/Command/maintenance.pm index dd65ac5..d8b8e44 100644 --- a/lib/Travelynx/Command/maintenance.pm +++ b/lib/Travelynx/Command/maintenance.pm @@ -1,4 +1,5 @@ package Travelynx::Command::maintenance; + # Copyright (C) 2020 Daniel Friesel # # SPDX-License-Identifier: MIT @@ -136,6 +137,22 @@ sub run { $tx->commit; + # Computing stats may take a while, but we've got all time in the + # world here. This means users won't have to wait when loading their + # own journey log. + say 'Generating missing stats ...'; + for + my $user ( $db->select( 'users', ['id'], { status => 1 } )->hashes->each ) + { + $tx = $db->begin; + $self->app->journeys->generate_missing_stats( uid => $user->{id} ); + $self->app->journeys->get_stats( + uid => $user->{id}, + year => $now->year + ); + $tx->commit; + } + # Add estimated polylines to journeys logged before 2020-01-28 $tx = $db->begin; diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index 16b41b2..27614ea 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -288,19 +288,6 @@ sub run { $self->app->traewelling_api->checkin( %{$candidate}, trip_id => $trip_id ); } - - # Computing yearly stats may take a while, but we've got all time in the - # world here. This means users won't have to wait when loading their - # own by-year journey log. - for my $user ( $db->select( 'users', 'id', { status => 1 } )->hashes->each ) - { - $self->app->journeys->get_stats( - uid => $user->{id}, - year => $now->year - ); - } - - # TODO wait until all background jobs have terminated } 1; -- cgit v1.2.3