From 12d812443db82265b1d58d650826955d64e9ba99 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 6 Jun 2022 11:24:21 +0100 Subject: [PATCH] Bug 30848: Ensure we flush the cache as necessary --- C4/Biblio.pm | 2 +- Koha/AuthorisedValue.pm | 33 ++++++++++++++++++- Koha/ClassSource.pm | 7 +--- Koha/ItemType.pm | 8 ++--- Koha/Library.pm | 7 +--- Koha/Localization.pm | 29 ++++++++++++++++ admin/biblio_framework.pl | 2 ++ admin/marc_subfields_structure.pl | 2 ++ admin/marctagstructure.pl | 2 ++ .../Koha/Filter/ExpandAuthorizedValues.t | 2 +- 10 files changed, 73 insertions(+), 21 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index b032860543..93c675e622 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1523,7 +1523,7 @@ sub GetAuthorisedValueDesc { my $dbh = C4::Context->dbh; if ( $category ne "" ) { - $cache_key = "AVDescriptions"; + $cache_key = "AVDescriptions-" . $category; my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); if ( !$av_descriptions ) { $av_descriptions = { diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm index 8f97bb1ede..5f292de3e6 100644 --- a/Koha/AuthorisedValue.pm +++ b/Koha/AuthorisedValue.pm @@ -19,7 +19,7 @@ package Koha::AuthorisedValue; use Modern::Perl; - +use Koha::Caches; use Koha::Database; use base qw(Koha::Object Koha::Object::Limit::Library); @@ -34,6 +34,37 @@ Koha::AuthorisedValue - Koha Authorised value Object class =cut +=head3 store + +AuthorisedValue specific store to ensure relevant caches are flushed on change + +=cut + +sub store { + my ($self) = @_; + + my $flush = 0; + + if ( !$self->in_storage ) { + $flush = 1; + } + else { + my $self_from_storage = $self->get_from_storage; + $flush = 1 if ( $self_from_storage->lib ne $self->lib ); + $flush = 1 if ( $self_from_storage->lib_opac ne $self->lib_opac ); + } + + $self = $self->SUPER::store; + + if ($flush) { + my $cache = Koha::Caches->get_instance(); + my $key = "AVDescriptions-".$self->category; + $cache->clear_from_cache($key); + } + + return $self; +} + =head3 opac_description my $description = $av->opac_description(); diff --git a/Koha/ClassSource.pm b/Koha/ClassSource.pm index 0bd83b6296..a3be3bba96 100644 --- a/Koha/ClassSource.pm +++ b/Koha/ClassSource.pm @@ -54,12 +54,7 @@ sub store { if ($flush) { my $cache = Koha::Caches->get_instance(); - my @frameworks = - Koha::BiblioFrameworks->search()->get_column('frameworkcode'); - for my $frameworkcode (@frameworks) { - my $key = "MarcAVStructure-$frameworkcode"; - $cache->clear_from_cache($key); - } + $cache->clear_from_cache('ClassSources'); } return $self; diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 495b410d7b..04ea8453e9 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -61,12 +61,8 @@ sub store { if ($flush) { my $cache = Koha::Caches->get_instance(); - my @frameworks = - Koha::BiblioFrameworks->search()->get_column('frameworkcode'); - for my $frameworkcode (@frameworks) { - my $key = "MarcAVStructure-$frameworkcode"; - $cache->clear_from_cache($key); - } + my $key = "enItemTypeDescriptions"; + $cache->clear_from_cache($key); } return $self; diff --git a/Koha/Library.pm b/Koha/Library.pm index 381237443a..5bd13a9b68 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -61,12 +61,7 @@ sub store { if ($flush) { my $cache = Koha::Caches->get_instance(); - my @frameworks = - Koha::BiblioFrameworks->search()->get_column('frameworkcode'); - for my $frameworkcode (@frameworks) { - my $key = "MarcAVStructure-$frameworkcode"; - $cache->clear_from_cache($key); - } + $cache->clear_from_cache('LibraryNames'); } return $self; diff --git a/Koha/Localization.pm b/Koha/Localization.pm index 3f698303c4..c700c42d6e 100644 --- a/Koha/Localization.pm +++ b/Koha/Localization.pm @@ -21,6 +21,35 @@ use Koha::Database; use base qw(Koha::Object); +=head1 NAME + +Koha::Localization - Koha Localization type Object class + +=head1 API + +=head2 Class methods + +=cut + +=head3 store + +Localization specific store to ensure relevant caches are flushed on change + +=cut + +sub store { + my ($self) = @_; + $self = $self->SUPER::store; + + if ($self->entity eq 'itemtypes') { + my $cache = Koha::Caches->get_instance(); + my $key = $self->lang."ItemTypeDescriptions"; + $cache->clear_from_cache($key); + } + + return $self; +} + sub _type { return 'Localization'; } diff --git a/admin/biblio_framework.pl b/admin/biblio_framework.pl index 32f2ac11eb..4712f0ea72 100755 --- a/admin/biblio_framework.pl +++ b/admin/biblio_framework.pl @@ -80,6 +80,7 @@ if ( $op eq 'add_form' ) { $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); + $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); $op = 'list'; } elsif ( $op eq 'delete_confirm' ) { my $framework = Koha::BiblioFrameworks->find($frameworkcode); @@ -111,6 +112,7 @@ if ( $op eq 'add_form' ) { $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); + $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); $op = 'list'; } diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index a2117eb912..a492e5c568 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -309,6 +309,7 @@ elsif ( $op eq 'add_validate' ) { $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); + $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode"); exit; @@ -347,6 +348,7 @@ elsif ( $op eq 'delete_confirmed' ) { $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); + $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode"); exit; diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl index 7ce19f99ac..3514baca93 100755 --- a/admin/marctagstructure.pl +++ b/admin/marctagstructure.pl @@ -155,6 +155,7 @@ if ($op eq 'add_form') { $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); + $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); print $input->redirect("/cgi-bin/koha/admin/marctagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode"); exit; # END $OP eq ADD_VALIDATE @@ -180,6 +181,7 @@ if ($op eq 'add_form') { $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); + $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); $template->param( searchfield => $searchfield ); # END $OP eq DELETE_CONFIRMED ################## ITEMTYPE_CREATE ################################## diff --git a/t/db_dependent/Koha/Filter/ExpandAuthorizedValues.t b/t/db_dependent/Koha/Filter/ExpandAuthorizedValues.t index ebdf9bb873..d8f18af0de 100644 --- a/t/db_dependent/Koha/Filter/ExpandAuthorizedValues.t +++ b/t/db_dependent/Koha/Filter/ExpandAuthorizedValues.t @@ -62,7 +62,7 @@ subtest 'ExpandAuthorizedValues tests' => sub { my $cache = Koha::Caches->get_instance; $cache->clear_from_cache("MarcStructure-0-"); $cache->clear_from_cache("MarcStructure-1-"); - $cache->clear_from_cache("MarcAVStructure-1-"); + $cache->clear_from_cache("MarcCodedFields-"); $cache->clear_from_cache("default_value_for_mod_marc-"); $cache->clear_from_cache("MarcSubfieldStructure-"); -- 2.20.1