diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-08-14 21:50:55 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-08-14 21:50:55 +0200 |
commit | 43fc820e0c4843716c4de612538b17c72530d8e2 (patch) | |
tree | a75d6600d65f468e735a007ca3c27de60945fcf8 /lib/Travelynx.pm | |
parent | c5af2fec5bfbff8469ecf770dbd67718b8fc9c78 (diff) |
add_route_timestamps: do not re-request trip id if it is already known2.8.17
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-x | lib/Travelynx.pm | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index e48310e..230441d 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -1372,17 +1372,28 @@ sub startup { my $route = $in_transit->{route}; my $train_id = $train->train_id; - # TODO get_tripid_p is only needed on the first call, afterwards the tripid is known. - $self->hafas->get_tripid_p( train => $train )->then( + my $tripid_promise; + + if ( $in_transit->{data}{trip_id} ) { + $tripid_promise + = Mojo::Promise->resolve( $in_transit->{data}{trip_id} ); + } + else { + $tripid_promise = $self->hafas->get_tripid_p( train => $train ); + } + + $tripid_promise->then( sub { my ($trip_id) = @_; - $self->in_transit->update_data( - uid => $uid, - db => $db, - data => { trip_id => $trip_id }, - train_id => $train_id, - ); + if ( not $in_transit->{extra_data}{trip_id} ) { + $self->in_transit->update_data( + uid => $uid, + db => $db, + data => { trip_id => $trip_id }, + train_id => $train_id, + ); + } return $self->hafas->get_route_p( train => $train, |