From 8c130f0466b85b78bae189bc2e9d82af445fb4c4 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 28 Mar 2024 10:55:05 -0400 Subject: [PATCH] Bug 36447: Circ rules slow to load when many itemtypes and categories It seems that we loop all categories and item types to build the circ matrix. We should only loop over values that have actually been used in circulation rules. Test Plan: 1) Create 1000 itemtypes and category codes. You can use the following script: use t::lib::TestBuilder; my $builder = t::lib::TestBuilder->new(); $builder->build( { source => 'Category' } ) for 0..1000; $builder->build( { source => 'Itemtype' } ) for 0..1000; 2) Note the lengthy load time for smart-rules.pl 3) Apply this patch 4) Restart all the things! 5) Reload the page 6) Note the much faster load time! --- admin/smart-rules.pl | 19 +++++++++++++------ .../prog/en/modules/admin/smart-rules.tt | 13 ++----------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index f5f168f44f4..16faa8b06ca 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -739,6 +739,11 @@ my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['des my $itemtypes = Koha::ItemTypes->search_with_localization; +my @used_categorycodes = + Koha::CirculationRules->search( {}, { columns => ['categorycode'], distinct => 1, } )->get_column('categorycode'); +my @used_itemtypes = + Koha::CirculationRules->search( {}, { columns => ['itemtype'], distinct => 1, } )->get_column('itemtype'); + my $humanbranch = ( $branch ne '*' ? $branch : undef ); my $all_rules = Koha::CirculationRules->search({ branchcode => $humanbranch }); @@ -753,12 +758,14 @@ while ( my $r = $all_rules->next ) { $template->param(show_branch_cat_rule_form => 1); $template->param( - patron_categories => $patron_categories, - itemtypeloop => $itemtypes, - humanbranch => $humanbranch, - current_branch => $branch, - definedbranch => $definedbranch, - all_rules => $rules, + used_categorycodes => \@used_categorycodes, + used_itemtypes => \@used_itemtypes, + patron_categories => $patron_categories, + itemtypeloop => $itemtypes, + 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 f536ef97601..1109b0e99ce 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 @@ -12,17 +12,8 @@ [% SET branchcode = humanbranch || undef %] -[% SET categorycodes = [] %] -[% FOREACH pc IN patron_categories %] - [% categorycodes.push( pc.id ) %] -[% END %] -[% categorycodes.push(undef) %] - -[% SET itemtypes = [] %] -[% FOREACH i IN itemtypeloop %] - [% itemtypes.push( i.itemtype ) %] -[% END %] -[% itemtypes.push(undef) %] +[% SET categorycodes = used_categorycodes %] +[% SET itemtypes = used_itemtypes %] [% INCLUDE 'doc-head-open.inc' %] [% FILTER collapse %] -- 2.30.2