From c5005ffa9ce22a89f12c3b271aef6045acb13155 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 17 Feb 2020 12:54:56 +0100 Subject: [PATCH] Bug 24670: Fetch all circulation rules at once to fix perf regression Signed-off-by: Lisette Scheer Signed-off-by: Martin Renvoize --- admin/smart-rules.pl | 9 ++- .../prog/en/modules/admin/smart-rules.tt | 60 ++++++++++--------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index dc8033b7f5..45c566eba1 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -562,7 +562,13 @@ my $itemtypes = Koha::ItemTypes->search_with_localization; my $humanbranch = ( $branch ne '*' ? $branch : undef ); -my $definedbranch = Koha::CirculationRules->search({ branchcode => $humanbranch })->count ? 1 : 0; +my $all_rules = Koha::CirculationRules->search({ branchcode => $humanbranch }); +my $definedbranch = $all_rules->count ? 1 : 0; + +while ( my $r = $all_rules->next ) { + $r = $r->unblessed; + $rules->{ $r->{categorycode} }->{ $r->{itemtype} }->{ $r->{rule_name} } = $r->{rule_value}; +} $template->param(show_branch_cat_rule_form => 1); @@ -572,6 +578,7 @@ $template->param( humanbranch => $humanbranch, current_branch => $branch, definedbranch => $definedbranch, + all_rules => $rules, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index e40138b31b..e0f50bf619 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -123,36 +123,38 @@ [% SET row_count = 0 %] [% FOREACH c IN categorycodes %] + [% SET c = '' UNLESS c.defined %] [% FOREACH i IN itemtypes %] - [% SET note = CirculationRules.Search( branchcode, c, i, 'note' ) %] - [% SET maxissueqty = CirculationRules.Search( branchcode, c, i, 'maxissueqty' ) %] - [% SET maxonsiteissueqty = CirculationRules.Search( branchcode, c, i, 'maxonsiteissueqty' ) %] - [% SET issuelength = CirculationRules.Search( branchcode, c, i, 'issuelength' ) %] - [% SET lengthunit = CirculationRules.Search( branchcode, c, i, 'lengthunit' ) %] - [% SET hardduedate = CirculationRules.Search( branchcode, c, i, 'hardduedate' ) %] - [% SET hardduedatecompare = CirculationRules.Search( branchcode, c, i, 'hardduedatecompare' ) %] - [% SET fine = CirculationRules.Search( branchcode, c, i, 'fine' ) %] - [% SET chargeperiod = CirculationRules.Search( branchcode, c, i, 'chargeperiod' ) %] - [% SET chargeperiod_charge_at = CirculationRules.Search( branchcode, c, i, 'chargeperiod_charge_at' ) %] - [% SET firstremind = CirculationRules.Search( branchcode, c, i, 'firstremind' ) %] - [% SET overduefinescap = CirculationRules.Search( branchcode, c, i, 'overduefinescap' ) %] - [% SET cap_fine_to_replacement_price = CirculationRules.Search( branchcode, c, i, 'cap_fine_to_replacement_price' ) %] - [% SET finedays = CirculationRules.Search( branchcode, c, i, 'finedays' ) %] - [% SET maxsuspensiondays = CirculationRules.Search( branchcode, c, i, 'maxsuspensiondays' ) %] - [% SET suspension_chargeperiod = CirculationRules.Search( branchcode, c, i, 'suspension_chargeperiod' ) %] - [% SET renewalsallowed = CirculationRules.Search( branchcode, c, i, 'renewalsallowed' ) %] - [% SET renewalperiod = CirculationRules.Search( branchcode, c, i, 'renewalperiod' ) %] - [% SET norenewalbefore = CirculationRules.Search( branchcode, c, i, 'norenewalbefore' ) %] - [% SET auto_renew = CirculationRules.Search( branchcode, c, i, 'auto_renew' ) %] - [% SET no_auto_renewal_after = CirculationRules.Search( branchcode, c, i, 'no_auto_renewal_after' ) %] - [% SET no_auto_renewal_after_hard_limit = CirculationRules.Search( branchcode, c, i, 'no_auto_renewal_after_hard_limit' ) %] - [% SET reservesallowed = CirculationRules.Search( branchcode, c, i, 'reservesallowed' ) %] - [% SET holds_per_day = CirculationRules.Search( branchcode, c, i, 'holds_per_day' ) %] - [% SET holds_per_record = CirculationRules.Search( branchcode, c, i, 'holds_per_record' ) %] - [% SET onshelfholds = CirculationRules.Search( branchcode, c, i, 'onshelfholds' ) %] - [% SET opacitemholds = CirculationRules.Search( branchcode, c, i, 'opacitemholds' ) %] - [% SET article_requests = CirculationRules.Search( branchcode, c, i, 'article_requests' ) %] - [% SET rentaldiscount = CirculationRules.Search( branchcode, c, i, 'rentaldiscount' ) %] + [% SET i = '' UNLESS i.defined %] + [% SET note = all_rules.$c.$i.note %] + [% SET maxissueqty = all_rules.$c.$i.maxissueqty %] + [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %] + [% SET issuelength = all_rules.$c.$i.issuelength %] + [% SET lengthunit = all_rules.$c.$i.lengthunit %] + [% SET hardduedate = all_rules.$c.$i.hardduedate %] + [% SET hardduedatecompare = all_rules.$c.$i.hardduedatecompare %] + [% SET fine = all_rules.$c.$i.fine %] + [% SET chargeperiod = all_rules.$c.$i.chargeperiod %] + [% SET chargeperiod_charge_at = all_rules.$c.$i.chargeperiod_charge_at %] + [% SET firstremind = all_rules.$c.$i.firstremind %] + [% SET overduefinescap = all_rules.$c.$i.overduefinescap %] + [% SET cap_fine_to_replacement_price = all_rules.$c.$i.cap_fine_to_replacement_price %] + [% SET finedays = all_rules.$c.$i.finedays %] + [% SET maxsuspensiondays = all_rules.$c.$i.maxsuspensiondays %] + [% SET suspension_chargeperiod = all_rules.$c.$i.suspension_chargeperiod %] + [% SET renewalsallowed = all_rules.$c.$i.renewalsallowed %] + [% SET renewalperiod = all_rules.$c.$i.renewalperiod %] + [% SET norenewalbefore = all_rules.$c.$i.norenewalbefore %] + [% SET auto_renew = all_rules.$c.$i.auto_renew %] + [% SET no_auto_renewal_after = all_rules.$c.$i.no_auto_renewal_after %] + [% SET no_auto_renewal_after_hard_limit = all_rules.$c.$i.no_auto_renewal_after_hard_limit %] + [% SET reservesallowed = all_rules.$c.$i.reservesallowed %] + [% SET holds_per_day = all_rules.$c.$i.holds_per_day %] + [% SET holds_per_record = all_rules.$c.$i.holds_per_record %] + [% SET onshelfholds = all_rules.$c.$i.onshelfholds %] + [% SET opacitemholds = all_rules.$c.$i.opacitemholds %] + [% SET article_requests = all_rules.$c.$i.article_requests %] + [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %] [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %] [% IF show_rule %] -- 2.20.1