Bug 26000: Make exception_holidays cache with branch in key

In light of 25723 offering a simpler solution here.
This would just let us avoid backporting larger changes, but this can be
marked as a duplicate if 25723 is preferred to this change

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
This commit is contained in:
Nick Clemens 2020-07-17 11:31:29 +00:00 committed by Aleisha Amohia
parent 45f3645aeb
commit 1d9737486c
3 changed files with 11 additions and 12 deletions

View File

@ -278,7 +278,7 @@ sub insert_single_holiday {
# changed the 'single_holidays' table, lets force/reset its cache
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
$cache->clear_from_cache( 'exception_holidays') ;
$cache->clear_from_cache( 'exception_holidays_'.$self->{branchcode}) ;
return $self;
@ -323,7 +323,7 @@ sub insert_exception_holiday {
# changed the 'single_holidays' table, lets force/reset its cache
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
$cache->clear_from_cache( 'exception_holidays') ;
$cache->clear_from_cache( 'exception_holidays_'.$self->{branchcode}) ;
return $self;
}
@ -424,7 +424,7 @@ UPDATE special_holidays SET title = ?, description = ?
# changed the 'single_holidays' table, lets force/reset its cache
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
$cache->clear_from_cache( 'exception_holidays') ;
$cache->clear_from_cache( 'exception_holidays_'.$self->{branchcode}) ;
return $self;
}
@ -467,7 +467,7 @@ UPDATE special_holidays SET title = ?, description = ?
# changed the 'single_holidays' table, lets force/reset its cache
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
$cache->clear_from_cache( 'exception_holidays') ;
$cache->clear_from_cache( 'exception_holidays_'.$self->{branchcode}) ;
return $self;
}
@ -548,7 +548,7 @@ sub delete_holiday {
# changed the 'single_holidays' table, lets force/reset its cache
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
$cache->clear_from_cache( 'exception_holidays') ;
$cache->clear_from_cache( 'exception_holidays_'.$self->{branchcode}) ;
return $self;
}
@ -579,7 +579,7 @@ sub delete_holiday_range {
# changed the 'single_holidays' table, lets force/reset its cache
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
$cache->clear_from_cache( 'exception_holidays') ;
$cache->clear_from_cache( 'exception_holidays_'.$self->{branchcode}) ;
}
@ -633,7 +633,7 @@ sub delete_exception_holiday_range {
# changed the 'single_holidays' table, lets force/reset its cache
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
$cache->clear_from_cache( 'exception_holidays') ;
$cache->clear_from_cache( 'exception_holidays_'.$self->{branchcode}) ;
}
=head2 isHoliday

View File

@ -55,12 +55,13 @@ sub _init {
sub exception_holidays {
my ( $self ) = @_;
my $branch = $self->{branchcode};
my $cache = Koha::Caches->get_instance();
my $cached = $cache->get_from_cache('exception_holidays');
my $key = 'exception_holidays_'.$branch;
my $cached = $cache->get_from_cache($key);
return $cached if $cached;
my $dbh = C4::Context->dbh;
my $branch = $self->{branchcode};
my $exception_holidays_sth = $dbh->prepare(
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1'
);
@ -77,7 +78,7 @@ sub exception_holidays {
}
$self->{exception_holidays} =
DateTime::Set->from_datetimes( dates => $dates );
$cache->set_in_cache( 'exception_holidays', $self->{exception_holidays} );
$cache->set_in_cache( $key, $self->{exception_holidays} );
return $self->{exception_holidays};
}

View File

@ -78,7 +78,6 @@ fixtures_ok [
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays' ) ;
$cache->clear_from_cache( 'exception_holidays' ) ;
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
my $cal = Koha::Calendar->new( branchcode => 'MPL' );
@ -336,5 +335,4 @@ subtest 'days_mode parameter' => sub {
END {
$cache->clear_from_cache( 'single_holidays' ) ;
$cache->clear_from_cache( 'exception_holidays' ) ;
};