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

Journey->update: Keep route data if it has been shortened

Partial fix for #313
parent 3f722f5d
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -337,7 +337,6 @@ sub update {
		db            => $db,
		journey_id    => $journey_id,
		with_datetime => 1,
		with_route_datetime => 1,
	);

	eval {
@@ -431,7 +430,25 @@ sub update {
			)->rows;
		}
		if ( exists $opt{route} ) {
			my @new_route = map { [ $_, undef, {} ] } @{ $opt{route} };

			# If $opt{route} is a subset of $journey->{route}, we can recycle all data
			my @new_route;
			my $new_route_i = 0;
			for my $old_route_i ( 0 .. $#{ $journey->{route} } ) {
				if ( $journey->{route}[$old_route_i][0] eq
					$opt{route}[$new_route_i] )
				{
					$new_route_i += 1;
					push( @new_route, $journey->{route}[$old_route_i] );
				}
			}

			# Otherwise, we need to fetch stop IDs so that polylines remain usable
			# (This is still TODO)
			if ( @new_route != @{ $opt{route} } ) {
				@new_route = map { [ $_, undef, {} ] } @{ $opt{route} };
			}

			$rows = $db->update(
				'journeys',
				{