From 511c0f0e86268f1df8c1219216d9b1cfa0d36f2e Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 22 Mar 2019 08:51:05 +0000 Subject: [PATCH] Bug 17385: (QA follow-up) Add caching Performance: We should add caching in CustomXSLTExportList. Note: This resolves the lack of an intranet test in the former patch too. Test plan: Run t/db_dependent/XSLT.t Signed-off-by: Marcel de Rooy Signed-off-by: David Nind --- C4/XSLT.pm | 8 ++++++++ t/db_dependent/XSLT.t | 15 +++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 7da42cdc39..c6871002d8 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -28,6 +28,7 @@ use C4::Koha qw( xml_escape ); use C4::Biblio qw( GetAuthorisedValueDesc GetFrameworkCode GetMarcStructure ); use Koha::AuthorisedValues; use Koha::ItemTypes; +use Koha::Caches; use Koha::XSLT::Base; use Koha::Libraries; use Koha::Recalls; @@ -485,6 +486,12 @@ sub CustomXSLTExportList { my $opac = shift; # opac (1) vs intranet (0) return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/; + # Check the cache first + my $cache = Koha::Caches->get_instance; + my $key = $opac ? 'CustomXSLTExportListOPAC' : 'CustomXSLTExportListIntra'; + my $cached_val = $cache->get_from_cache($key); + return $cached_val if $cached_val; + my @tabFiles; my $dir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') . @@ -521,6 +528,7 @@ sub CustomXSLTExportList { push @tabFiles, \%row; } } + $cache->set_in_cache( $key, [ @tabFiles ] ); return \@tabFiles; } 1; diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index 69c8828af6..ed9f39adf9 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -19,14 +19,17 @@ our $schema = Koha::Database->new->schema; # Here we go $schema->storage->txn_begin; -subtest 'CustomXSLTExportList: Check export options' => sub { - plan tests => 2; +subtest 'CustomXSLTExportList: Caching' => sub { + plan tests => 1; t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); - my $list = C4::XSLT::CustomXSLTExportList(1); - is( @$list>0, 1, 'We expect at least one result: simple export' ); - t::lib::Mocks::mock_preference('OpacExportOptions', 'dc'); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); + my $list = C4::XSLT::CustomXSLTExportList(1); + push @$list, { nonsense => 1 }; + $cache->set_in_cache( 'CustomXSLTExportListOPAC', $list ); + my $n = @$list; $list = C4::XSLT::CustomXSLTExportList(1); - is( @$list, 0, 'We expect an empty list now' ); + is( @$list, $n, 'This list comes from the cache and that is fine' ); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); }; subtest 'transformMARCXML4XSLT tests' => sub { -- 2.25.1