Bug 21450: Cache authorities search using term and auth_type
authorNick Clemens <nick@bywatersolutions.com>
Fri, 28 Sep 2018 14:58:20 +0000 (14:58 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 30 May 2019 20:24:27 +0000 (21:24 +0100)
This is a simple fix to prevent incorrect caching of results when using
link_bibs_to_authorities

To test:
1 - Find or create a record with the same term in a subject and genre
heading
2 - Find or create authority records for the term as a subject and genre
type
3 - Run link bibs to authorities
4 - Verify both tags in the record are linked to the subject heading
5 - Aply patch
6 - Unlink the record and re-run the script (or just re-run)
7 - Each tag should be linked to correct authority

Signed-off-by: Frank Hansen <frank.hansen@ub.lu.se>

Signed-off-by: Liz Rea <wizzyrea@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 848a0d41fffba7df1be9f2584770112f0938beb0)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Linker/Default.pm

index b39557c..1fa395c 100644 (file)
@@ -30,12 +30,13 @@ sub get_link {
     my $heading     = shift;
     my $behavior    = shift || 'default';
     my $search_form = $heading->search_form();
+    my $auth_type = $heading->auth_type();
     my $authid;
     my $fuzzy = 0;
 
-    if ( $self->{'cache'}->{$search_form}->{'cached'} ) {
-        $authid = $self->{'cache'}->{$search_form}->{'authid'};
-        $fuzzy  = $self->{'cache'}->{$search_form}->{'fuzzy'};
+    if ( $self->{'cache'}->{$search_form.$auth_type}->{'cached'} ) {
+        $authid = $self->{'cache'}->{$search_form.$auth_type}->{'authid'};
+        $fuzzy  = $self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'};
     }
     else {
 
@@ -72,9 +73,9 @@ sub get_link {
             }
         }
 
-        $self->{'cache'}->{$search_form}->{'cached'} = 1;
-        $self->{'cache'}->{$search_form}->{'authid'} = $authid;
-        $self->{'cache'}->{$search_form}->{'fuzzy'}  = $fuzzy;
+        $self->{'cache'}->{$search_form.$auth_type}->{'cached'} = 1;
+        $self->{'cache'}->{$search_form.$auth_type}->{'authid'} = $authid;
+        $self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'}  = $fuzzy;
     }
     return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
 }
@@ -84,11 +85,12 @@ sub update_cache {
     my $heading     = shift;
     my $authid      = shift;
     my $search_form = $heading->search_form();
+    my $auth_type = $heading->auth_type();
     my $fuzzy = 0;
 
-    $self->{'cache'}->{$search_form}->{'cached'} = 1;
-    $self->{'cache'}->{$search_form}->{'authid'} = $authid;
-    $self->{'cache'}->{$search_form}->{'fuzzy'}  = $fuzzy;
+    $self->{'cache'}->{$search_form.$auth_type}->{'cached'} = 1;
+    $self->{'cache'}->{$search_form.$auth_type}->{'authid'} = $authid;
+    $self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'}  = $fuzzy;
 }
 
 sub flip_heading {