Bugzilla – Attachment 107017 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 a hasref for lookup
Bug-25723-Use-a-hasref-for-lookup.patch (text/plain), 4.02 KB, created by
Joonas Kylmälä
on 2020-07-17 14:42:30 UTC
(
hide
)
Description:
Bug 25723: Use a hasref for lookup
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2020-07-17 14:42:30 UTC
Size:
4.02 KB
patch
obsolete
>From 47998ad19f5acee1a829ba4a78106eaac4509e6a Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 12 Jun 2020 16:30:28 +0100 >Subject: [PATCH] Bug 25723: Use a hasref for lookup >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Rather than using an array of dates and iterating them, use a hashref >and do a direct lookup > >Signed-off-by: Emma Perks <Emma.Perks2@uhb.nhs.uk> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi> >--- > Koha/Calendar.pm | 64 ++++++++++++++++++++++++++------------------------------ > 1 file changed, 30 insertions(+), 34 deletions(-) > >diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm >index 322f34b575..ec02fc5fad 100644 >--- a/Koha/Calendar.pm >+++ b/Koha/Calendar.pm >@@ -51,7 +51,7 @@ sub _init { > } > > sub exception_holidays { >- my ( $self ) = @_; >+ my ($self) = @_; > > my $cache = Koha::Caches->get_instance(); > my $exception_holidays = $cache->get_from_cache('exception_holidays'); >@@ -81,7 +81,7 @@ sub exception_holidays { > { expiry => 76800 } ); > } > >- return $exception_holidays->{$self->{branchcode}} // {}; >+ return $exception_holidays->{ $self->{branchcode} } // {}; > } > > sub is_exception_holiday { >@@ -92,8 +92,8 @@ sub is_exception_holiday { > } > > sub single_holidays { >- my ( $self, $date ) = @_; >- my $branchcode = $self->{branchcode}; >+ my ($self) = @_; >+ > my $cache = Koha::Caches->get_instance(); > my $single_holidays = $cache->get_from_cache('single_holidays'); > >@@ -106,42 +106,38 @@ sub single_holidays { > # ... > # } > >+ # Populate the cache if necessary > unless ($single_holidays) { > my $dbh = C4::Context->dbh; > $single_holidays = {}; > >- # push holidays for each branch >- my $branches_sth = >- $dbh->prepare('SELECT distinct(branchcode) FROM special_holidays'); >- $branches_sth->execute(); >- while ( my $br = $branches_sth->fetchrow ) { >- my $single_holidays_sth = $dbh->prepare( >-'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0' >- ); >- $single_holidays_sth->execute($br); >- >- my @ymd_arr; >- while ( my ( $day, $month, $year ) = >- $single_holidays_sth->fetchrow ) >- { >- my $dt = DateTime->new( >- day => $day, >- month => $month, >- year => $year, >- time_zone => 'floating', >- )->truncate( to => 'day' ); >- push @ymd_arr, $dt->ymd(''); >- } >- $single_holidays->{$br} = \@ymd_arr; >- } # br >+ # 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 } ) #24 hrs ; >+ { expiry => 76800 } ); > } > >- my $holidays = ( $single_holidays->{$branchcode} ); >- for my $hols (@$holidays ) { >- return 1 if ( $date == $hols ) #match ymds; >- } >+ return $single_holidays->{ $self->{branchcode} } // {}; >+} >+ >+sub is_single_holiday { >+ my ( $self, $date ) = @_; >+ >+ return 1 if ( $self->single_holidays->{$date} ); > return 0; > } > >@@ -307,7 +303,7 @@ sub is_holiday { > return 1; > } > >- if ($self->single_holidays( $ymd ) == 1 ) { >+ if ($self->is_single_holiday( $ymd ) == 1 ) { > return 1; > } > >-- >2.11.0
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