Summary: | Improve speed of koha-preferences CLI tool (by using minimal dbh) | ||
---|---|---|---|
Product: | Koha | Reporter: | David Cook <dcook> |
Component: | Command-line Utilities | Assignee: | David Cook <dcook> |
Status: | RESOLVED FIXED | QA Contact: | Martin Renvoize (ashimema) <martin.renvoize> |
Severity: | enhancement | ||
Priority: | P5 - low | CC: | lucas, martin.renvoize, robin |
Version: | Main | Keywords: | Academy |
Hardware: | All | ||
OS: | All | ||
See Also: | https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34088 | ||
Change sponsored?: | --- | Patch complexity: | --- |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: |
This change refactors the koha-preferences CLI tool to use different internal database libraries in order to gain a speed performance improvement.
|
Version(s) released in: |
24.11.00
|
Circulation function: | |||
Bug Depends on: | |||
Bug Blocks: | 37682 | ||
Attachments: |
Bug 37657: Make koha-preferences CLI tool faster
Bug 37657: Make koha-preferences CLI tool faster |
Description
David Cook
2024-08-16 03:44:35 UTC
If I use Koha::Database->dbh instead of C4::Context->dbh, I can get "misc/admin/koha-preferences get SearchEngine" down from 0.914s to 0.328s. That's pretty impressive. However, if I remove the other Koha::/C4:: module loads from the top of the script, I can reduce it even further down to 0.087s. That's the kind of speed I'm really looking for here. -- I reckon lazy-loading the modules needed for each command isn't a bad way to go. Even if the community doesn't accept it, I'm going to do it locally anyway, as the speed improvement is just too good not to do. But perhaps I'll use this bug report to do that first speed improvement, and then open a separate one to do the lazy-loading to get the final speed improvement, since that one will be more controversial. Created attachment 170490 [details] [review] Bug 37657: Make koha-preferences CLI tool faster By using Koha::Database->dbh() to use a minimal database handle which doesn't preload the whole DBIx::Class schema, we're able to run the same command 2-3 times faster. This is beneficial when running the tool in a loop which runs the command serially one by one. Test plan: 1. time misc/admin/koha-preferences get SearchEngine 2. Note time is about 1 second 3. time misc/admin/koha-preferences dump 4. Note time is about 1 second 5. Create sysprefs.yml --- marcflavour: MARC21 viewMARC: 1 6. time misc/admin/koha-preferences load -i sysprefs.yml 7. Apply patch 8. Repeat the koha-preferences commands above 9. Note that the command runs about 2-3 times faster Note: I think the only place that "misc/admin/koha-preferences" is used directly by Koha is in debian/scripts/koha-functions.sh where it is used in the function "is_elasticsearch_enabled". So I think this is a very low risk change as well. Created attachment 170520 [details] [review] Bug 37657: Make koha-preferences CLI tool faster By using Koha::Database->dbh() to use a minimal database handle which doesn't preload the whole DBIx::Class schema, we're able to run the same command 2-3 times faster. This is beneficial when running the tool in a loop which runs the command serially one by one. Test plan: 1. time misc/admin/koha-preferences get SearchEngine 2. Note time is about 1 second 3. time misc/admin/koha-preferences dump 4. Note time is about 1 second 5. Create sysprefs.yml Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Trivial, clear, meaningful patch that certainly reduced memory footprint and increased speed for these scripts. Going straight for Passing QA. I don't entirely understand why C4::Context->dbh isn't just a passthrough for Koha::Database->dbh at this point.. I can't really see why you'd want a Schema loaded when you're clearly only asking for the database handle back... one for another bug though that. Pushed for 24.11! Well done everyone, thank you! |