Unverified Commit 6f46ecec authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

history: compute stats directly in overview

parent 734e6c9a
Loading
Loading
Loading
Loading
+5 −12
Original line number Diff line number Diff line
@@ -36,25 +36,18 @@ latter is quite expensive and could cause long load times on the history pages.

Adding this data for all journeys stored so far would take minutes to hours
depending on database size, and is therefore not done as part of this
migration. Please run the following command at your earliest convenience:
migration. Please run the following commands at your earliest convenience:

$ carton exec perl index.pl stats compute-distances
$ carton exec perl index.pl stats purge-cache

(adjust "carton exec" prefix, "sudo -u ...", environment variables, etc.
as necessary for your setup -- use the same invocation as for, e.g.,
"perl index.pl maintenance")

The command can operate while the travelynx services are running. Until this
post-migration script has completed, users may be confronted with invalid or
missing distance data in their history view for the current year and month.

There is a short window in which such invalid distances may be cached -- this
will happen whenever a user completes a journey and then opens the history page
for the current year or the current month. If you want to ensure that all
cached data is valid, you can follow up with the follow two commands:

$ carton exec perl index.pl stats purge
$ carton exec perl index.pl stats refresh-all
The command can operate while the travelynx services are running. Until these
post-migration steps has been completed, users may observe invalid or missing
distance data in their travel statistics for the current year and month.

EOF

+3 −3
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ sub compute_distances {
	say "Added travel distances to $updated of $i journeys";
}

sub purge {
sub purge_cache {
	my ($self) = @_;

	say 'Purging cached journey stats: TRUNCATE TABLE journey_stats';
@@ -88,8 +88,8 @@ sub run {
	elsif ( $cmd eq 'refresh-all' ) {
		$self->refresh_all(@arg);
	}
	elsif ( $cmd eq 'purge' ) {
		$self->purge(@arg);
	elsif ( $cmd eq 'purge-cache' ) {
		$self->purge_cache(@arg);
	}

}
+17 −3
Original line number Diff line number Diff line
@@ -1122,10 +1122,16 @@ sub get_years {
	for my $year (@years) {
		my $stats = $self->stats_cache->get(
			uid   => $opt{uid},
			year  => $year,
			year  => $year->[0],
			month => 0,
		);
		$year->[2] = $stats // {};
		if ( not $stats ) {
			$stats = $self->get_stats(
				uid  => $opt{uid},
				year => $year->[0],
			);
		}
		$year->[2] = $stats;
	}
	return @years;
}
@@ -1162,8 +1168,16 @@ sub get_months_for_year {
				month => $row->{month}
			);

			if ( not $stats ) {
				$stats = $self->get_stats(
					uid   => $opt{uid},
					year  => $year,
					month => $row->{month},
				);
			}

			# undef -> no journeys for this month; empty hash -> no cached stats
			$ret[ $row->{month} - 1 ][2] = $stats // {};
			$ret[ $row->{month} - 1 ][2] = $stats;
		}
	}
	return @ret;