Bug 33214: (follow-up) Consistency on key names
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 13 Mar 2023 19:42:26 +0000 (16:42 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 13 Mar 2023 19:42:33 +0000 (16:42 -0300)
This patch makes GetAuthorisedValueDesc used cache keys match what we
discussed on the bug, which seems to have been lost on some rebase and
highlighted by failing tests.

I also add some more cache flushes.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Biblio.pm
t/db_dependent/Koha/Filter/ExpandCodedFields.t
t/db_dependent/Koha/Item.t

index e90eb11..1af5e12 100644 (file)
@@ -1385,7 +1385,7 @@ sub GetAuthorisedValueDesc {
 
         #---- branch
         if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-            $cache_key = "LibraryNames";
+            $cache_key = "libraries:name";
             my $libraries = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
             if ( !$libraries ) {
                 $libraries = {
@@ -1403,7 +1403,7 @@ sub GetAuthorisedValueDesc {
         if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
             my $lang = C4::Languages::getlanguage;
             $lang //= 'en';
-            $cache_key = $lang . 'ItemTypeDescriptions';
+            $cache_key = 'itemtype:description:' . $lang;
             my $itypes = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
             if ( !$itypes ) {
                 $itypes =
@@ -1435,7 +1435,7 @@ sub GetAuthorisedValueDesc {
 
     my $dbh = C4::Context->dbh;
     if ( $category ne "" ) {
-        $cache_key = "AVDescriptions-" . $category;
+        $cache_key = "AV_descriptions:" . $category;
         my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
         if ( !$av_descriptions ) {
             $av_descriptions = {
index 04912a4..25df74b 100755 (executable)
@@ -73,6 +73,11 @@ subtest 'ExpandCodedFields tests' => sub {
 
     my $cache = Koha::Caches->get_instance;
     $cache->clear_from_cache("MarcCodedFields-");
+    # Clear GetAuthorisedValueDesc-generated cache
+    $cache->clear_from_cache("libraries:name");
+    $cache->clear_from_cache("itemtype:description:en");
+    $cache->clear_from_cache("cn_sources:description");
+    $cache->clear_from_cache("AV_descriptions:LOST");
 
     C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
     $biblio = Koha::Biblios->find( $biblio->biblionumber);
index bd56d19..d9252ef 100755 (executable)
@@ -1463,6 +1463,7 @@ subtest 'strings_map() tests' => sub {
     $cache->clear_from_cache("libraries:name");
     $cache->clear_from_cache("itemtype:description:en");
     $cache->clear_from_cache("cn_sources:description");
+    $cache->clear_from_cache("AV_descriptions:LOST");
 
     # Recreating subfields just to be sure tests will be ok
     # 1 => av (LOST)