Bugzilla – Attachment 105789 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: Drop DateTime::Set dependancy
Bug-25723-Drop-DateTimeSet-dependancy.patch (text/plain), 3.57 KB, created by
Martin Renvoize (ashimema)
on 2020-06-12 10:55:49 UTC
(
hide
)
Description:
Bug 25723: Drop DateTime::Set dependancy
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-06-12 10:55:49 UTC
Size:
3.57 KB
patch
obsolete
>From a937062d4e05ce2161e79b0e3b42e6b8c4b2ec6d Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 12 Jun 2020 11:53:49 +0100 >Subject: [PATCH] Bug 25723: Drop DateTime::Set dependancy > >This patch removes our use of DateTime::Set and replaces it with a quick >hashref implimentation >--- > Koha/Calendar.pm | 57 +++++++++++++++++++++++++++--------------------- > 1 file changed, 32 insertions(+), 25 deletions(-) > >diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm >index ef397cd838..a41fff8491 100644 >--- a/Koha/Calendar.pm >+++ b/Koha/Calendar.pm >@@ -4,7 +4,6 @@ use warnings; > use 5.010; > > use DateTime; >-use DateTime::Set; > use DateTime::Duration; > use C4::Context; > use Koha::Caches; >@@ -53,32 +52,40 @@ sub _init { > } > > sub exception_holidays { >- my ( $self ) = @_; >+ my ( $self, $date ) = @_; >+ >+ my $cache = Koha::Caches->get_instance(); >+ my $exception_holidays = $cache->get_from_cache('exception_holidays'); > >- my $cache = Koha::Caches->get_instance(); >- my $cached = $cache->get_from_cache('exception_holidays'); >- return $cached if $cached; >+ # Populate the cache is necessary >+ unless ($exception_holidays) { >+ my $dbh = C4::Context->dbh; >+ $exception_holidays = {}; >+ >+ # Push holidays for each branch >+ my $exception_holidays_sth = $dbh->prepare( >+'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 1' >+ ); >+ $exception_holidays_sth->execute(); >+ my $dates = []; >+ while ( my ( $day, $month, $year, $branch ) = >+ $exception_holidays_sth->fetchrow ) >+ { >+ push @{ $exception_holidays->{$branch} }, >+ sprintf( "%04d", $year ) >+ . sprintf( "%02d", $month ) >+ . sprintf( "%02d", $day ); >+ } >+ $cache->set_in_cache( 'exception_holidays', $exception_holidays, >+ { expiry => 76800 } ); >+ } > >- my $dbh = C4::Context->dbh; >+ # Return if we match > my $branch = $self->{branchcode}; >- my $exception_holidays_sth = $dbh->prepare( >-'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1' >- ); >- $exception_holidays_sth->execute( $branch ); >- my $dates = []; >- while ( my ( $day, $month, $year ) = $exception_holidays_sth->fetchrow ) { >- push @{$dates}, >- DateTime->new( >- day => $day, >- month => $month, >- year => $year, >- time_zone => "floating", >- )->truncate( to => 'day' ); >+ for my $hols ( @{ $exception_holidays->{$branch} } ) { >+ return 1 if ( $date == $hols ); > } >- $self->{exception_holidays} = >- DateTime::Set->from_datetimes( dates => $dates ); >- $cache->set_in_cache( 'exception_holidays', $self->{exception_holidays} ); >- return $self->{exception_holidays}; >+ return 0; > } > > sub single_holidays { >@@ -250,13 +257,14 @@ sub is_holiday { > my $localdt = $dt->clone(); > my $day = $localdt->day; > my $month = $localdt->month; >+ my $ymd = $localdt->ymd('') ; > > #Change timezone to "floating" before doing any calculations or comparisons > $localdt->set_time_zone("floating"); > $localdt->truncate( to => 'day' ); > > >- if ( $self->exception_holidays->contains($localdt) ) { >+ if ( $self->exception_holidays( $ymd ) == 1 ) { > # exceptions are not holidays > return 0; > } >@@ -277,7 +285,6 @@ sub is_holiday { > return 1; > } > >- my $ymd = $localdt->ymd('') ; > if ($self->single_holidays( $ymd ) == 1 ) { > return 1; > } >-- >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