From 36714861cec0ff572e4f8b4e9ee865b395b89dad Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Wed, 17 Sep 2025 21:39:59 +0200 Subject: Journey->update: Keep route data if it has been shortened Partial fix for #313 --- lib/Travelynx/Model/Journeys.pm | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'lib/Travelynx/Model') diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 19af659..0ee436a 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -333,11 +333,10 @@ sub update { my $rows; my $journey = $self->get_single( - uid => $uid, - db => $db, - journey_id => $journey_id, - with_datetime => 1, - with_route_datetime => 1, + uid => $uid, + db => $db, + journey_id => $journey_id, + with_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', { -- cgit v1.2.3