diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-12-12 17:24:24 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-12-12 17:24:24 +0100 |
commit | 879b3b38150960786341489a44609ac300725413 (patch) | |
tree | e2015ccfee8b5e60a1d24a7a2e24fd1e985f3310 /lib | |
parent | 7bb1f4fea0568a3964dcc4bf1ba793a6ccdc6338 (diff) |
fix caching fuckup introduced in 2e5a1b0a79e3a54e159cf598b2a0d398109a7bf41.21.3
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travelynx/Helper/DBDB.pm | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Travelynx/Helper/DBDB.pm b/lib/Travelynx/Helper/DBDB.pm index fbee1b9..f78f9ec 100644 --- a/lib/Travelynx/Helper/DBDB.pm +++ b/lib/Travelynx/Helper/DBDB.pm @@ -34,7 +34,7 @@ sub has_wagonorder_p { my $cache = $self->{cache}; my $promise = Mojo::Promise->new; - if ( my $content = $cache->get($url) ) { + if ( my $content = $cache->get("HEAD $url") ) { if ( $content eq 'n' ) { return $promise->reject; } @@ -48,18 +48,18 @@ sub has_wagonorder_p { sub { my ($tx) = @_; if ( $tx->result->is_success ) { - $cache->set( $url, 'a' ); + $cache->set( "HEAD $url", 'a' ); $promise->resolve('a'); } else { - $cache->set( $url, 'n' ); + $cache->set( "HEAD $url", 'n' ); $promise->reject; } return; } )->catch( sub { - $cache->set( $url, 'n' ); + $cache->set( "HEAD $url", 'n' ); $promise->reject; return; } @@ -90,11 +90,17 @@ sub get_wagonorder_p { ->then( sub { my ($tx) = @_; - my $body = decode( 'utf-8', $tx->res->body ); - my $json = JSON->new->decode($body); - $cache->freeze( $url, $json ); - $promise->resolve($json); + if ( $tx->result->is_success ) { + my $body = decode( 'utf-8', $tx->res->body ); + my $json = JSON->new->decode($body); + $cache->freeze( $url, $json ); + $promise->resolve($json); + } + else { + my $code = $tx->code; + $promise->reject("HTTP ${code}"); + } return; } )->catch( |