Skip to content

Commit

Permalink
BWS-PKG - Bug 36447: Circ rules slow to load when many itemtypes and …
Browse files Browse the repository at this point in the history
…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 <[email protected]>

Signed-off-by: Marcel de Rooy <[email protected]>
  • Loading branch information
kylemhall committed Apr 11, 2024
1 parent e0233d2 commit 1b136be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
19 changes: 13 additions & 6 deletions admin/smart-rules.pl
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@

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 });
Expand All @@ -753,12 +758,14 @@
$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;

Expand Down
13 changes: 2 additions & 11 deletions koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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 %]
Expand Down

0 comments on commit 1b136be

Please sign in to comment.