Bug 28172 - Optimize Koha::Plugins::GetPlugins
Summary: Optimize Koha::Plugins::GetPlugins
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement with 8 votes (vote)
Assignee: Julian Maurice
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 7923
  Show dependency treegraph
 
Reported: 2021-04-20 07:15 UTC by Julian Maurice
Modified: 2022-03-10 08:08 UTC (History)
1 user (show)

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


Attachments
Bug 28172: [DO NOT PUSH] Test script for GetPlugins (1.60 KB, patch)
2021-04-20 07:16 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 28172: Optimize Koha::Plugins::GetPlugins (4.86 KB, patch)
2021-04-20 07:16 UTC, Julian Maurice
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Maurice 2021-04-20 07:15:02 UTC

    
Comment 1 Julian Maurice 2021-04-20 07:16:03 UTC
Created attachment 119870 [details] [review]
Bug 28172: [DO NOT PUSH] Test script for GetPlugins
Comment 2 Julian Maurice 2021-04-20 07:16:07 UTC
Created attachment 119871 [details] [review]
Bug 28172: Optimize Koha::Plugins::GetPlugins

Instead of doing one SQL query for retrieving a list of plugin classes
(filtered or not by a method name) + one SQL query for each loaded
plugin (to look up the 'enabled' status), we can do a single SQL query,
fetching only enabled plugins, and do the method check using `can`.

It allows to use the Module::Load::Conditional cache when requesting
only enabled modules, which gives a great performance boost

Also, call get_metadata only if needed

Test plan:
1. Make sure you have some plugins enabled
2. Apply the 1st patch ("Test script for GetPlugins")
3. Run the test script several times, copy each result into a file A
4. Apply the other patch(es)
5. Run the test script several times, copy each result into another
   file B
6. Compare the results. Times in file B should be smaller than in file A
Comment 3 Julian Maurice 2021-04-20 07:19:38 UTC
Without the patch:

% ./test_getplugins.pl 
2 plugins detected, 2 enabled
First 2 calls to GetPlugins: 0.533s
1000 calls to GetPlugins: 3.505s
1000 calls to GetPlugins with method = "unknown_method": 0.824s
1000 calls to GetPlugins with all = 1: 3.580s

With the patch:

% ./test_getplugins.pl
2 plugins detected, 2 enabled
First 2 calls to GetPlugins: 0.535s
1000 calls to GetPlugins: 1.502s
1000 calls to GetPlugins with method = "unknown_method": 0.730s
1000 calls to GetPlugins with all = 1: 3.795s