fix caching fuckup introduced in 2e5a1b0a79

This commit is contained in:
Daniel Friesel 2021-12-12 17:24:24 +01:00
parent 7bb1f4fea0
commit 879b3b3815

View file

@ -34,7 +34,7 @@ sub has_wagonorder_p {
my $cache = $self->{cache}; my $cache = $self->{cache};
my $promise = Mojo::Promise->new; my $promise = Mojo::Promise->new;
if ( my $content = $cache->get($url) ) { if ( my $content = $cache->get("HEAD $url") ) {
if ( $content eq 'n' ) { if ( $content eq 'n' ) {
return $promise->reject; return $promise->reject;
} }
@ -48,18 +48,18 @@ sub has_wagonorder_p {
sub { sub {
my ($tx) = @_; my ($tx) = @_;
if ( $tx->result->is_success ) { if ( $tx->result->is_success ) {
$cache->set( $url, 'a' ); $cache->set( "HEAD $url", 'a' );
$promise->resolve('a'); $promise->resolve('a');
} }
else { else {
$cache->set( $url, 'n' ); $cache->set( "HEAD $url", 'n' );
$promise->reject; $promise->reject;
} }
return; return;
} }
)->catch( )->catch(
sub { sub {
$cache->set( $url, 'n' ); $cache->set( "HEAD $url", 'n' );
$promise->reject; $promise->reject;
return; return;
} }
@ -90,11 +90,17 @@ sub get_wagonorder_p {
->then( ->then(
sub { sub {
my ($tx) = @_; my ($tx) = @_;
my $body = decode( 'utf-8', $tx->res->body );
if ( $tx->result->is_success ) {
my $body = decode( 'utf-8', $tx->res->body );
my $json = JSON->new->decode($body); my $json = JSON->new->decode($body);
$cache->freeze( $url, $json ); $cache->freeze( $url, $json );
$promise->resolve($json); $promise->resolve($json);
}
else {
my $code = $tx->code;
$promise->reject("HTTP ${code}");
}
return; return;
} }
)->catch( )->catch(