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!

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 4e04ff28b6)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Kyle Hall 2024-03-28 10:55:05 -04:00 committed by Fridolin Somers
parent 067522e35e
commit c13b941429
2 changed files with 15 additions and 17 deletions

View file

@ -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;

View file

@ -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' %]
<title>[% FILTER collapse %]