From 1711127e1268b39f3253955f8bde22a253f93f79 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 17 Jul 2020 11:31:29 +0000 Subject: [PATCH] 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 Signed-off-by: Aleisha Amohia (cherry picked from commit 1d9737486c8aad3a419d1b4ad22ba1a43ee243d3) Signed-off-by: Victor Grousset/tuxayo --- C4/Calendar.pm | 14 +++++++------- Koha/Calendar.pm | 7 ++++--- t/Calendar.t | 2 -- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/C4/Calendar.pm b/C4/Calendar.pm index 321aad76d5..27a9d4b34e 100644 --- a/C4/Calendar.pm +++ b/C4/Calendar.pm @@ -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 diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 07faad58dd..8f9a2a4023 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -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}; } diff --git a/t/Calendar.t b/t/Calendar.t index e390696a44..9a18a85bb1 100755 --- a/t/Calendar.t +++ b/t/Calendar.t @@ -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' ) ; }; -- 2.39.5