diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-09-17 21:39:59 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-09-17 21:39:59 +0200 |
commit | 36714861cec0ff572e4f8b4e9ee865b395b89dad (patch) | |
tree | cdc871604ebb02109c155d2d84e2c182e9880087 /lib/Travelynx | |
parent | 3f722f5df9073a6cc541cbfa9cc546b144d44bc7 (diff) |
Journey->update: Keep route data if it has been shortened
Partial fix for #313
Diffstat (limited to 'lib/Travelynx')
-rwxr-xr-x | lib/Travelynx/Model/Journeys.pm | 29 |
1 files changed, 23 insertions, 6 deletions
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', { |