From a647d3c971002158e30a3c86f967105dc36d018c 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 Content-Type: text/plain; charset=utf-8 Performance: We should add caching in CustomXSLTExportList. Test plan: Run t/db_dependent/XSLT.t Signed-off-by: Marcel de Rooy --- C4/XSLT.pm | 8 +++++++- t/db_dependent/XSLT.t | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 73b18933b6..7f9f614a22 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -30,6 +30,7 @@ use C4::Biblio; use C4::Circulation; use C4::Reserves; use Koha::AuthorisedValues; +use Koha::Caches; use Koha::ItemTypes; use Koha::XSLT_Handler; use Koha::Libraries; @@ -379,8 +380,12 @@ sub CustomXSLTExportList { my $opac = shift; # opac (1) vs intranet (0) return [] if C4::Context->preference('OpacExportOptions') !~ /custom/; - my @tabFiles; + # Check the cache first + my $cache = Koha::Caches->get_instance; + my $cached_val = $cache->get_from_cache('CustomXSLTExportList'); + 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() . @@ -414,6 +419,7 @@ sub CustomXSLTExportList { push @tabFiles, \%row; } } + $cache->set_in_cache( 'CustomXSLTExportList', [ @tabFiles ] ); return \@tabFiles; } diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index 5f91cdb44b..1b1fb85e87 100644 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -1,11 +1,13 @@ use Modern::Perl; -use Test::More tests => 1; +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; @@ -20,4 +22,17 @@ subtest 'CustomXSLTExportList: Check export options' => sub { $list = C4::XSLT::CustomXSLTExportList(1); is( @$list, 0, 'We expect an empty list now' ); }; + +subtest 'CustomXSLTExportList: Caching' => sub { + plan tests => 1; + t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); + $cache->clear_from_cache('CustomXSLTExportList'); + my $list = C4::XSLT::CustomXSLTExportList(1); + push @$list, { nonsense => 1 }; + $cache->set_in_cache( 'CustomXSLTExportList', $list ); + my $n = @$list; + $list = C4::XSLT::CustomXSLTExportList(1); + is( @$list, $n, 'This list comes from the cache and that is fine' ); + $cache->clear_from_cache('CustomXSLTExportList'); +}; $schema->storage->txn_rollback; -- 2.11.0