Bug 36668 - Excessive whitespace/newlines in circulation rules editor may cause slow loads with large rules sets
Summary: Excessive whitespace/newlines in circulation rules editor may cause slow load...
Status: Patch doesn't apply
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Kyle M Hall (khall)
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-22 13:09 UTC by Kyle M Hall (khall)
Modified: 2024-08-27 14:41 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 36668: Excessive whitespace/newlines in circulation rules editor may cause slow loads with large rules sets (108.02 KB, patch)
2024-04-22 16:07 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 36668: Excessive whitespace/newlines in circulation rules editor may cause slow loads with large rules sets (108.07 KB, patch)
2024-05-03 10:56 UTC, Pedro Amorim
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle M Hall (khall) 2024-04-22 13:09:03 UTC
Simply put we have a lot of SET lines and such in our circ rules editor template. For large rule sets all the newlines add up and can balloon the rendered html size to many megabytes! We should add a newline chomper to these lines.
Comment 1 Kyle M Hall (khall) 2024-04-22 16:07:52 UTC
Created attachment 165325 [details] [review]
Bug 36668: Excessive whitespace/newlines in circulation rules editor may cause slow loads with large rules sets

Simply put we have a lot of SET lines and such in our circ rules editor template. For large rule sets all the newlines add up and can balloon the rendered html size to many megabytes! We should add a newline chomper to these lines.

1) Generate a large number of circ rules with the following perl script

use Koha::CirculationRules;
use Koha::Patron::Categories;
use Koha::ItemTypes;

use t::lib::TestBuilder;
my $builder = t::lib::TestBuilder->new();
$builder->build( { source => 'Category' } ) for 0 .. 80;
$builder->build( { source => 'Itemtype' } ) for 0 .. 80;

C4::Context->dbh->do("
    INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value )
    SELECT NULL, categories.categorycode, itemtypes.itemtype, 'issuelength', 5
    FROM categories JOIN itemtypes;"
);

2) Open the network debugging on your web browser
3) Load smart-rules.pl
4) Notice the size of the file
5) Apply this patch
6) Restart all the things!
7) Reload smart-rules.pl
8) Note the file size has been drastically reduced!
Comment 2 Pedro Amorim 2024-05-03 10:56:56 UTC
Created attachment 166107 [details] [review]
Bug 36668: Excessive whitespace/newlines in circulation rules editor may cause slow loads with large rules sets

Simply put we have a lot of SET lines and such in our circ rules editor template. For large rule sets all the newlines add up and can balloon the rendered html size to many megabytes! We should add a newline chomper to these lines.

1) Generate a large number of circ rules with the following perl script

use Koha::CirculationRules;
use Koha::Patron::Categories;
use Koha::ItemTypes;

use t::lib::TestBuilder;
my $builder = t::lib::TestBuilder->new();
$builder->build( { source => 'Category' } ) for 0 .. 80;
$builder->build( { source => 'Itemtype' } ) for 0 .. 80;

C4::Context->dbh->do("
    INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value )
    SELECT NULL, categories.categorycode, itemtypes.itemtype, 'issuelength', 5
    FROM categories JOIN itemtypes;"
);

2) Open the network debugging on your web browser
3) Load smart-rules.pl
4) Notice the size of the file
5) Apply this patch
6) Restart all the things!
7) Reload smart-rules.pl
8) Note the file size has been drastically reduced!

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 3 Pedro Amorim 2024-05-03 11:04:16 UTC
Hey Kyle, some testing notes (thanks for the test script btw A+):

Before patch:
Time: 22-26 seconds / Size: 911kB

After patch:
Time: 20-25 seconds / Size: 530kB

From my testing, this patch reduces the page size, but it does not fix the "slow load" issue.

My suggestion to fix this for the future would be to implement infinite scroll on this page, i.e. additional circulation rules entries are loaded as the user navigates downwards (would say it's likely not trivial for this page and it may introduce issues I'm not considering atm).
Bug 36641 is adding a circulation rules REST endpoint and although I don't think it would directly help for this specific use case it would be a starting point.
Sorry for the tangent, just something to (maybe) discuss!
Comment 4 Nick Clemens (kidclamp) 2024-05-03 11:29:27 UTC
(In reply to Pedro Amorim from comment #3)
> Hey Kyle, some testing notes (thanks for the test script btw A+):
> 
> Before patch:
> Time: 22-26 seconds / Size: 911kB
> 
> After patch:
> Time: 20-25 seconds / Size: 530kB
> 
> From my testing, this patch reduces the page size, but it does not fix the
> "slow load" issue.

36672 should help with the slow load - it turns out we are fetching individual rules for later sections of the page, rather than using the ones already fetched in the script

> My suggestion to fix this for the future would be to implement infinite
> scroll on this page, i.e. additional circulation rules entries are loaded as
> the user navigates downwards (would say it's likely not trivial for this
> page and it may introduce issues I'm not considering atm).
> Bug 36641 is adding a circulation rules REST endpoint and although I don't
> think it would directly help for this specific use case it would be a
> starting point.
> Sorry for the tangent, just something to (maybe) discuss!

Interesting, but slightly frightening
Comment 5 Lucas Gass (lukeg) 2024-08-27 14:41:18 UTC
Unfortanuetly, this one no longer applies cleanly to main.