diff --git a/C4/SIP/Sip/Configuration.pm b/C4/SIP/Sip/Configuration.pm index b8e5075e03..a6757ea6cc 100644 --- a/C4/SIP/Sip/Configuration.pm +++ b/C4/SIP/Sip/Configuration.pm @@ -47,7 +47,11 @@ sub get_configuration { if ($sip2_resource_last_modified) { $cache->set_in_cache( 'sip2_config_read_timestamp', $sip2_resource_last_modified ); } else { - $cache->set_in_cache( 'sip2_config_read_timestamp', dt_from_string()->epoch ); + + # Set sip2_resource_last_modified so config won't be read from db on each request + my $now = dt_from_string()->epoch; + $cache->set_in_cache( 'sip2_resource_last_modified', $now ); + $cache->set_in_cache( 'sip2_config_read_timestamp', $now ); } my $cfg; diff --git a/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t b/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t index 3e5982fa31..275f09c372 100755 --- a/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t +++ b/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::NoWarnings; use Test::MockModule; @@ -181,6 +181,34 @@ subtest 'config_timestamp is updated when database configuration changes' => sub $schema->storage->txn_rollback; }; +subtest 'get_configuration() reseeds sip2_resource_last_modified when missing from cache' => sub { + + plan tests => 4; + + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + my $cache = Koha::Caches->get_instance(); + $cache->clear_from_cache('sip2_resource_last_modified'); + $cache->clear_from_cache('sip2_config_read_timestamp'); + + is( $cache->get_from_cache('sip2_resource_last_modified'), undef, 'sip2_resource_last_modified cleared' ); + + C4::SIP::Sip::Configuration->get_configuration( undef, { listeners => {} } ); + + my $resource_last_modified = $cache->get_from_cache('sip2_resource_last_modified'); + my $config_read_timestamp = $cache->get_from_cache('sip2_config_read_timestamp'); + + ok( $resource_last_modified, 'sip2_resource_last_modified is repopulated' ); + ok( $config_read_timestamp, 'sip2_config_read_timestamp is set' ); + is( + $config_read_timestamp, $resource_last_modified, + 'sip2_config_read_timestamp matches sip2_resource_last_modified so subsequent requests skip a full reload' + ); + + $schema->storage->txn_rollback; +}; + subtest 'Atomicupdate skips migrating data if provided config file doesn\'t exist or is unreadable' => sub { plan tests => 1;