From 14c8489c15f6c0fe0496e2ff769615956a536ba1 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 | 9 ++++++++- t/db_dependent/XSLT.t | 18 +++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index d53df4d643..27bddd44ba 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -31,6 +31,7 @@ use C4::Circulation; use C4::Reserves; use Koha::AuthorisedValues; use Koha::ItemTypes; +use Koha::Caches; use Koha::XSLT::Base; use Koha::Libraries; @@ -414,8 +415,13 @@ sub CustomXSLTExportList { my $opac = shift; # opac (1) vs intranet (0) return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/; - my @tabFiles; + # 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') . '/' . C4::Context->preference( $opac ? "opacthemes" : "template") . '/' . C4::Languages::getlanguage() . @@ -449,6 +455,7 @@ sub CustomXSLTExportList { push @tabFiles, \%row; } } + $cache->set_in_cache( $key, [ @tabFiles ] ); return \@tabFiles; } diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index 06f74327e5..5abb8b7c09 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -3,22 +3,26 @@ use Test::More tests => 2; use t::lib::Mocks; use C4::XSLT; +use Koha::Caches; use Koha::Database; our $schema = Koha::Database->new->schema; +our $cache = Koha::Caches->get_instance; # 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 'buildKohaItemsNamespace status tests' => sub { plan tests => 13; my $itype = $builder->build_object({ class => 'Koha::ItemTypes' }); -- 2.17.1