Bugzilla – Attachment 160234 Details for
Bug 35579
marcrecord2csv searches authorised values inefficiently
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35579: Cache authorised value lookup by MARC field
Bug-35579-Cache-authorised-value-lookup-by-MARC-fi.patch (text/plain), 3.76 KB, created by
Julian Maurice
on 2023-12-22 12:48:27 UTC
(
hide
)
Description:
Bug 35579: Cache authorised value lookup by MARC field
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2023-12-22 12:48:27 UTC
Size:
3.76 KB
patch
obsolete
>From ddf2f53570526e70d877e99b04a7367bfa645fe5 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Fri, 15 Dec 2023 06:02:17 +0000 >Subject: [PATCH] Bug 35579: Cache authorised value lookup by MARC field > >This patch adds a "get_descriptions_by_marc_field" method >which caches AuthorisedValue descriptions when searched by >MARC field, which is used when exporting MARC to CSV. > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> >--- > C4/Record.pm | 14 ++++++++------ > Koha/AuthorisedValues.pm | 32 ++++++++++++++++++++++++++++++++ > 2 files changed, 40 insertions(+), 6 deletions(-) > >diff --git a/C4/Record.pm b/C4/Record.pm >index 9f0d21c4910..33d18b86bd1 100644 >--- a/C4/Record.pm >+++ b/C4/Record.pm >@@ -576,9 +576,12 @@ sub marcrecord2csv { > # If it is a subfield > my @loop_values; > if (defined $tag->{subfieldtag} ) { >- my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, tagsubfield => $tag->{subfieldtag}, }); >- $av = $av->count ? $av->unblessed : []; >- my $av_description_mapping = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av }; >+ my $av_description_mapping = Koha::AuthorisedValues->get_descriptions_by_marc_field( >+ { >+ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, >+ tagsubfield => $tag->{subfieldtag}, >+ } >+ ); > # For each field > foreach my $field (@fields) { > my @subfields = $field->subfield( $tag->{subfieldtag} ); >@@ -589,9 +592,8 @@ sub marcrecord2csv { > > # Or a field > } else { >- my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, }); >- $av = $av->count ? $av->unblessed : []; >- my $authvalues = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av }; >+ my $authvalues = Koha::AuthorisedValues->get_descriptions_by_marc_field( >+ { frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, } ); > > foreach my $field ( @fields ) { > my $value; >diff --git a/Koha/AuthorisedValues.pm b/Koha/AuthorisedValues.pm >index 822be037eaa..377d1de5526 100644 >--- a/Koha/AuthorisedValues.pm >+++ b/Koha/AuthorisedValues.pm >@@ -141,6 +141,38 @@ sub get_descriptions_by_koha_field { > return @descriptions; > } > >+=head3 get_descriptions_by_marc_field >+ >+ Return cached descriptions when looking up by MARC field/subfield >+ >+=cut >+ >+sub get_descriptions_by_marc_field { >+ my ( $self, $params ) = @_; >+ my $frameworkcode = $params->{frameworkcode} || ''; >+ my $tagfield = $params->{tagfield}; >+ my $tagsubfield = $params->{tagsubfield}; >+ >+ return {} unless defined $params->{tagfield}; >+ >+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance; >+ my $cache_key = "AV_descriptions_by_MARC:$frameworkcode:$tagfield"; >+ if ($tagsubfield) { >+ $cache_key .= ":$tagsubfield"; >+ } >+ >+ my $cached = $memory_cache->get_from_cache($cache_key); >+ return $cached if $cached; >+ >+ my $descriptions = {}; >+ my @avs = $self->search_by_marc_field($params)->as_list; >+ foreach my $av (@avs) { >+ $descriptions->{ $av->authorised_value } = $av->lib; >+ } >+ $memory_cache->set_in_cache( $cache_key, $descriptions ); >+ return $descriptions; >+} >+ > sub categories { > my ( $self ) = @_; > my $rs = $self->_resultset->search( >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35579
:
159858
|
159936
|
159975
|
159976
| 160234 |
160235