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.

Test plan:
0. Do not apply the patch yet!
1. Go to http://localhost:8081/cgi-bin/koha/tools/csv-profiles.pl
2. Add a CSV profile with the default values and using the following for the "Profile MARC fields":
000|001|003|005|006|007|008|010|015|016|020|022|040|050|082|100|110|111|130|240|243|245|246|247|250|260|300|336|337|338|440|490|500|501|505|520|530|600|610|611|630|648|650|651|690|700|710|711|856|887|942|995|952|952$c
3. Create a new List
4. Add all the database's bibs to that list using SQL like the following (where the shelfnumber equals the number for your list):
insert into virtualshelfcontents (shelfnumber,biblionumber,borrowernumber) select 1,biblionumber,51 from biblio;
5. Go to that list in the staff interface
6. Download that list using your CSV profile
7. Apply the patch
8. koha-plack --reload kohadev
9. Download that list using your CSV profile
10. Note that the output is the same, but that the output completes much more quickly after applying the patch

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
David Cook 2023-12-15 06:02:17 +00:00 committed by Katrin Fischer
parent 47ffdaf6f4
commit 78c0e8df8d
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 40 additions and 6 deletions

View file

@ -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;

View file

@ -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(