diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-01-11 22:33:54 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-01-11 22:33:54 +0100 |
commit | fa21ea4bce78edbf3649d656b98d96f88b0b0aaf (patch) | |
tree | 1855ddf34c1ee70e5fcc7d521f3ecfccd119926e | |
parent | dcdea4247b6457202ce746814ff44d249c32d8b5 (diff) |
Wagonorder: refactor dbdb requests
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 2 | ||||
-rw-r--r-- | lib/DBInfoscreen/Helper/Wagonorder.pm | 52 | ||||
-rw-r--r-- | templates/_train_details.html.ep | 2 |
3 files changed, 14 insertions, 42 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 2eb7b12..85a94e5 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -775,7 +775,7 @@ sub render_train { if ( $self->param('detailed') ) { my $cycle_req = Mojo::Promise->new; push( @requests, $cycle_req ); - $self->wagonorder->has_umlauf_p( $result->train_no )->then( + $self->wagonorder->has_cycle_p( $result->train_no )->then( sub { $departure->{has_cycle} = 1; } diff --git a/lib/DBInfoscreen/Helper/Wagonorder.pm b/lib/DBInfoscreen/Helper/Wagonorder.pm index 5904d86..d303d18 100644 --- a/lib/DBInfoscreen/Helper/Wagonorder.pm +++ b/lib/DBInfoscreen/Helper/Wagonorder.pm @@ -57,12 +57,11 @@ sub is_available_p { return $promise; } -sub has_umlauf_p { - my ( $self, $train_no ) = @_; +sub head_dbdb_p { + my ( $self, $url ) = @_; my $promise = Mojo::Promise->new; - my $url = "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png"; my $cache = $self->{main_cache}; if ( my $content = $cache->get($url) ) { @@ -98,46 +97,19 @@ sub has_umlauf_p { return $promise; } -sub check_wagonorder_p { - my ( $self, $train_no, $wr_link ) = @_; - - my $promise = Mojo::Promise->new; +sub has_cycle_p { + my ( $self, $train_no ) = @_; - my $url - = "https://lib.finalrewind.org/dbdb/has_wagonorder/${train_no}/${wr_link}"; - my $cache = $self->{main_cache}; + return $self->head_dbdb_p( + "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png"); +} - if ( my $content = $cache->get($url) ) { - if ( $content eq 'y' ) { - return $promise->resolve; - } - else { - return $promise->reject; - } - } +sub check_wagonorder_p { + my ( $self, $train_no, $wr_link ) = @_; - $self->{user_agent}->request_timeout(5)->head_p( $url => $self->{header} ) - ->then( - sub { - my ($tx) = @_; - if ( $tx->result->is_success ) { - $cache->set( $url, 'y' ); - $promise->resolve; - } - else { - $cache->set( $url, 'n' ); - $promise->reject; - } - return; - } - )->catch( - sub { - $cache->set( $url, 'n' ); - $promise->reject; - return; - } - )->wait; - return $promise; + return $self->head_dbdb_p( + "https://lib.finalrewind.org/dbdb/has_wagonorder/${train_no}/${wr_link}" + ); } sub get_p { diff --git a/templates/_train_details.html.ep b/templates/_train_details.html.ep index 3a68c80..d55d3cb 100644 --- a/templates/_train_details.html.ep +++ b/templates/_train_details.html.ep @@ -229,7 +229,7 @@ </ul> <!-- mroute --> % } % if (param('detailed') and $departure->{has_cycle}) { - <div><a href="https://lib.finalrewind.org/dbdb/db_umlauf/<%= $departure->{train_no} %>.png">Umlaufplan</a></div> + <div class="db-attr"><a href="https://lib.finalrewind.org/dbdb/db_umlauf/<%= $departure->{train_no} %>.png">Umlaufplan</a></div> % } % if (param('detailed') and $details->{commonAttr}) { % if ($details->{attrVariants} and (not $details->{commonAttr}{vmax} or not $details->{commonAttr}{brakingPercentage})) { |