Mason James
5d256e6b4b
this patch adds Koha::Cache functionality to the 'single_holidays' table it is a performance patch for the problem described in BZ14315, only http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14315 it replaces slooow DateTime holiday objects with simple Ymd strings (19991230), then stores the strings in an @array using Koha::Cache it does not attempt to add caching to all holiday tables - just the single_holidays table (at this stage on my test (master-cd9a827); nytprof showed a time reduction of the single_holidays() sub - from 61.7s to 587ms here are some before/after nytprof runs, (really on master-cd9a827, not 3.20) http://x1.kohaaloha.com/i/nyt-bz14522-before/home-mason-g-k-3-20-x-Koha-Calendar-pm-1485-line.html#237 http://x1.kohaaloha.com/i/nyt-bz14522-after/home-mason-g-k-3-20-x-Koha-Calendar-pm-1485-line.html#280 to test... 1/ add a bunch of single_holidays to your test koha, (my table has 400 holiday rows) 2/ add a loong circ rule for an itemtype (my rule has 140 days) 3/ checkout an item to a user (took me 67 secs) apply patch... 4/ return item 5/ repeats steps 1..3, (took me 6 secs) 6/ add/change/delete some various single_holidays, via Home->Tools->Calendar ensure that your various changes have indeed saved correctly for extra points... 7/ run tests t/Calendar.t and t/db_dependent/Holidays.t, with all tests pass OK sudo koha-shell -c ' export PERL5LIB=/home/mason/g/k/master ; \ cd /home/mason/g/k/master ; perl t/Calendar.t ; perl t/db_dependent/Holidays.t ' testkoha 8/ run QA tool, with all tests pass OK sudo koha-shell -c ' \ export KOHA_CONF=/etc/koha/sites/mayo2/koha-conf.xml \ export PERL5LIB=/home/mason/g/k/master:/home/mason/qa-test-tools/ ; \ cd /home/mason/g/k/master ; perl /home/mason/qa-test-tools/koha-qa.pl -c 1 ' testkoha Signed-off-by: Nick Clemens <nick@quecheelibrary.org> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
152 lines
5.2 KiB
Perl
Executable file
152 lines
5.2 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
#FIXME: add a license
|
|
#FIXME: perltidy this file
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use CGI qw ( -utf8 );
|
|
|
|
use C4::Auth;
|
|
use C4::Output;
|
|
|
|
use Koha::Cache;
|
|
|
|
|
|
use C4::Calendar;
|
|
use DateTime;
|
|
|
|
my $input = new CGI;
|
|
my $dbh = C4::Context->dbh();
|
|
|
|
our $branchcode = $input->param('newBranchName');
|
|
my $originalbranchcode = $branchcode;
|
|
our $weekday = $input->param('newWeekday');
|
|
our $day = $input->param('newDay');
|
|
our $month = $input->param('newMonth');
|
|
our $year = $input->param('newYear');
|
|
my $day1;
|
|
my $month1;
|
|
my $year1;
|
|
my $dateofrange = $input->param('dateofrange');
|
|
our $title = $input->param('newTitle');
|
|
our $description = $input->param('newDescription');
|
|
our $newoperation = $input->param('newOperation');
|
|
my $allbranches = $input->param('allBranches');
|
|
|
|
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
|
|
my $isodate = C4::Dates->new($calendardate, 'iso');
|
|
$calendardate = $isodate->output('syspref');
|
|
|
|
my @dateend = split(/[\/-]/, $dateofrange);
|
|
if (C4::Context->preference("dateformat") eq "metric") {
|
|
$day1 = $dateend[0];
|
|
$month1 = $dateend[1];
|
|
$year1 = $dateend[2];
|
|
}elsif (C4::Context->preference("dateformat") eq "us") {
|
|
$month1 = $dateend[0];
|
|
$day1 = $dateend[1];
|
|
$year1 = $dateend[2];
|
|
} else {
|
|
$year1 = $dateend[0];
|
|
$month1 = $dateend[1];
|
|
$day1 = $dateend[2];
|
|
}
|
|
$title || ($title = '');
|
|
if ($description) {
|
|
$description =~ s/\r/\\r/g;
|
|
$description =~ s/\n/\\n/g;
|
|
} else {
|
|
$description = '';
|
|
}
|
|
|
|
# We make an array with holiday's days
|
|
our @holiday_list;
|
|
if ($year1 && $month1 && $day1){
|
|
my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
|
|
my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
|
|
|
|
for (my $dt = $first_dt->clone();
|
|
$dt <= $end_dt;
|
|
$dt->add(days => 1) )
|
|
{
|
|
push @holiday_list, $dt->clone();
|
|
}
|
|
}
|
|
|
|
if($allbranches) {
|
|
my $branch;
|
|
my @branchcodes = split(/\|/, $input->param('branchCodes'));
|
|
foreach $branch (@branchcodes) {
|
|
add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
|
|
}
|
|
} else {
|
|
add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
|
|
}
|
|
|
|
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
|
|
|
|
#FIXME: move add_holiday() to a better place
|
|
sub add_holiday {
|
|
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;
|
|
my $calendar = C4::Calendar->new(branchcode => $branchcode);
|
|
|
|
if ($newoperation eq 'weekday') {
|
|
unless ( $weekday && ($weekday ne '') ) {
|
|
# was dow calculated by javascript? original code implies it was supposed to be.
|
|
# if not, we need it.
|
|
$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
|
|
}
|
|
unless($calendar->isHoliday($day, $month, $year)) {
|
|
$calendar->insert_week_day_holiday(weekday => $weekday,
|
|
title => $title,
|
|
description => $description);
|
|
}
|
|
} elsif ($newoperation eq 'repeatable') {
|
|
unless($calendar->isHoliday($day, $month, $year)) {
|
|
$calendar->insert_day_month_holiday(day => $day,
|
|
month => $month,
|
|
title => $title,
|
|
description => $description);
|
|
}
|
|
} elsif ($newoperation eq 'holiday') {
|
|
unless($calendar->isHoliday($day, $month, $year)) {
|
|
$calendar->insert_single_holiday(day => $day,
|
|
month => $month,
|
|
year => $year,
|
|
title => $title,
|
|
description => $description);
|
|
}
|
|
|
|
} elsif ( $newoperation eq 'holidayrange' ) {
|
|
if (@holiday_list){
|
|
foreach my $date (@holiday_list){
|
|
unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
|
|
$calendar->insert_single_holiday(
|
|
day => $date->{local_c}->{day},
|
|
month => $date->{local_c}->{month},
|
|
year => $date->{local_c}->{year},
|
|
title => $title,
|
|
description => $description
|
|
);
|
|
}
|
|
}
|
|
}
|
|
} elsif ( $newoperation eq 'holidayrangerepeat' ) {
|
|
if (@holiday_list){
|
|
foreach my $date (@holiday_list){
|
|
unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
|
|
$calendar->insert_day_month_holiday(
|
|
day => $date->{local_c}->{day},
|
|
month => $date->{local_c}->{month},
|
|
title => $title,
|
|
description => $description
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# we updated the single_holidays table, so wipe its cache
|
|
my $cache = Koha::Cache->get_instance();
|
|
$cache->clear_from_cache( 'single_holidays') ;
|
|
}
|