Bugzilla – Attachment 105937 Details for
Bug 25723
Improve efficiency of holiday calculation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25723: Use the same code for single and exception holidays
Bug-25723-Use-the-same-code-for-single-and-excepti.patch (text/plain), 3.76 KB, created by
Jonathan Druart
on 2020-06-17 08:11:42 UTC
(
hide
)
Description:
Bug 25723: Use the same code for single and exception holidays
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-06-17 08:11:42 UTC
Size:
3.76 KB
patch
obsolete
>From cb467786f3deb9a49834aaa96228e49bda38eb62 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 17 Jun 2020 10:11:02 +0200 >Subject: [PATCH] Bug 25723: Use the same code for single and exception > holidays > >--- > Koha/Calendar.pm | 70 +++++++++++++++--------------------------------- > 1 file changed, 21 insertions(+), 49 deletions(-) > >diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm >index f15f804e8c..77fc509a83 100644 >--- a/Koha/Calendar.pm >+++ b/Koha/Calendar.pm >@@ -54,35 +54,44 @@ sub _init { > sub exception_holidays { > my ($self) = @_; > >- my $cache = Koha::Caches->get_instance(); >- my $exception_holidays = $cache->get_from_cache('exception_holidays'); >+ return $self->_holidays('exception'); >+} >+ >+sub _holidays { >+ my ( $self, $type ) = @_; >+ >+ die "Unknown type, only 'exception' or 'single' is supported" >+ unless $type eq 'exception' or $type eq 'single'; >+ >+ my $cache = Koha::Caches->get_instance(); >+ my $holidays = $cache->get_from_cache("${type}_holidays"); > > # Populate the cache is necessary >- unless ($exception_holidays) { >+ unless ($holidays) { > my $dbh = C4::Context->dbh; >- $exception_holidays = {}; >+ $holidays = {}; > > # Push holidays for each branch >- my $exception_holidays_sth = $dbh->prepare( >-'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 1' >+ my $holidays_sth = $dbh->prepare( >+ 'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = ?' > ); >- $exception_holidays_sth->execute(); >+ $holidays_sth->execute($type eq 'exception' ? 1 : 0); > my $dates = []; > while ( my ( $day, $month, $year, $branch ) = >- $exception_holidays_sth->fetchrow ) >+ $holidays_sth->fetchrow ) > { > my $datestring = > sprintf( "%04d", $year ) > . sprintf( "%02d", $month ) > . sprintf( "%02d", $day ); > >- $exception_holidays->{$branch}->{$datestring} = 1; >+ $holidays->{$branch}->{$datestring} = 1; > } >- $cache->set_in_cache( 'exception_holidays', $exception_holidays, >+ $cache->set_in_cache( "${type}_holidays", $holidays, > { expiry => 76800 } ); > } > >- return $exception_holidays->{ $self->{branchcode} } // {}; >+ return $holidays->{ $self->{branchcode} } // {}; > } > > sub is_exception_holiday { >@@ -95,44 +104,7 @@ sub is_exception_holiday { > sub single_holidays { > my ($self) = @_; > >- my $cache = Koha::Caches->get_instance(); >- my $single_holidays = $cache->get_from_cache('single_holidays'); >- >- # $single_holidays looks like: >- # { >- # CPL => [ >- # [0] 20131122, >- # ... >- # ], >- # ... >- # } >- >- # Populate the cache if necessary >- unless ($single_holidays) { >- my $dbh = C4::Context->dbh; >- $single_holidays = {}; >- >- # Push holidays for each branch >- my $single_holidays_sth = $dbh->prepare( >-'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 0' >- ); >- $single_holidays_sth->execute(); >- >- while ( my ( $day, $month, $year, $branch ) = >- $single_holidays_sth->fetchrow ) >- { >- my $datestring = >- sprintf( "%04d", $year ) >- . sprintf( "%02d", $month ) >- . sprintf( "%02d", $day ); >- >- $single_holidays->{$branch}->{$datestring} = 1; >- } >- $cache->set_in_cache( 'single_holidays', $single_holidays, >- { expiry => 76800 } ); >- } >- >- return $single_holidays->{ $self->{branchcode} } // {}; >+ return $self->_holidays('single'); > } > > sub is_single_holiday { >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25723
:
105789
|
105792
|
105793
|
105830
|
105831
|
105832
|
105833
|
105834
|
105835
|
105836
|
105936
|
105937
|
105939
|
105941
|
105947
|
105954
|
105955
|
105956
|
105957
|
105958
|
105959
|
105960
|
105961
|
105962
|
105963
|
105964
|
105965
|
105966
|
105967
|
105968
|
105969
|
105970
|
106991
|
106992
|
106993
|
106994
|
106995
|
106996
|
106997
|
106998
|
106999
|
107000
|
107001
|
107002
|
107003
|
107004
|
107005
|
107006
|
107007
|
107008
|
107009
|
107010
|
107013
|
107014
|
107015
|
107016
|
107017
|
107018
|
107019
|
107020
|
107021
|
107022
|
107023
|
107025