From 6e381f73f41da9f9229f5553ad7f003f188ccb18 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Tue, 1 Nov 2022 15:30:01 +0100 Subject: [PATCH] Bug 32060: Improve performance of columns_to_str To test: 1) Ensure tests in t/db_dependent/Koha/Item.t all pass 2) Go to a biblio (preferably as serial) with many items and click "New" -> "New item" and take not of the response time. 3) Apply the patch. 4) Ensure tests in t/db_dependent/Koha/Item.t still pass 5) Repeat step 1), the response time should be substantially improved. Sponsored-by: Gothenburg University Library --- Koha/Item.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 7251a8a094f..0d64aa47542 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1051,9 +1051,15 @@ This is meant to be used for display purpose only. sub columns_to_str { my ( $self ) = @_; + my $cache = Koha::Cache::Memory::Lite->get_instance(); + my $cache_key = 'Item_columns_to_str_biblio_frameworkcode:' . $self->biblionumber; - my $frameworkcode = $self->biblio->frameworkcode; - my $tagslib = C4::Biblio::GetMarcStructure(1, $frameworkcode); + my $frameworkcode = $cache->get_from_cache($cache_key); + unless ( defined $frameworkcode ) { + $frameworkcode = $self->biblio->frameworkcode; + $cache->set_in_cache($cache_key, $frameworkcode); + } + my $tagslib = C4::Biblio::GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } ); my ( $itemtagfield, $itemtagsubfield) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" ); my $columns_info = $self->_result->result_source->columns_info; @@ -1064,7 +1070,7 @@ sub columns_to_str { next if $column eq 'more_subfields_xml'; - my $value = $self->$column; + my $value = $self->_result()->get_column($column); # Maybe we need to deal with datetime columns here, but so far we have damaged_on, itemlost_on and withdrawn_on, and they are not linked with kohafield if ( not defined $value or $value eq "" ) { -- 2.40.0