Bug 29454: Use Koha Cache Memory Lite to stash itemtype descriptions for template plugin

Returns empty string if given item type is undefined or unknown

To test:
1 - Add 1000 items to a record, of varying item types
2 - Bring up the details page
3 - Note time to load
4 - Apply patch
5 - Reload page and compare to previous
6 - Confirm information is correct
7 - Confirm some performance benefit

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 3df28469c5)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2021-12-13 14:44:18 +00:00 committed by Lucas Gass
parent 01bde643f2
commit f4595b7bbd
1 changed files with 19 additions and 2 deletions

View File

@ -22,15 +22,32 @@ use Modern::Perl;
use Template::Plugin;
use base qw( Template::Plugin );
use Koha::Cache::Memory::Lite;
use Koha::ItemTypes;
sub GetDescription {
my ( $self, $itemtypecode, $want_parent ) = @_;
return q{} unless defined $itemtypecode;
my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
my $cache_key = $want_parent ? "Itemtype_parent_description:".$itemtypecode : "Itemtype_description:" . $itemtypecode;
my $cached = $memory_cache->get_from_cache($cache_key);
return $cached if $cached;
my $itemtype = Koha::ItemTypes->find( $itemtypecode );
return q{} unless $itemtype;
unless ($itemtype) {
$memory_cache->set_in_cache( $cache_key, q{} );
return q{};
}
my $parent;
$parent = $itemtype->parent if $want_parent;
return $parent ? $parent->translated_description . "->" . $itemtype->translated_description : $itemtype->translated_description;
my $description = $parent ? $parent->translated_description . "->" . $itemtype->translated_description : $itemtype->translated_description;
$memory_cache->set_in_cache( $cache_key, $description );
return $description;
}
sub Get {