Bug 28172

Summary: Optimize Koha::Plugins::GetPlugins
Product: Koha Reporter: Julian Maurice <julian.maurice>
Component: Plugin architectureAssignee: Julian Maurice <julian.maurice>
Status: RESOLVED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: david, fridolin.somers
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29672
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on:    
Bug Blocks: 7923    
Attachments: Bug 28172: [DO NOT PUSH] Test script for GetPlugins
Bug 28172: Optimize Koha::Plugins::GetPlugins
Bug 28172: [DO NOT PUSH] Test script for GetPlugins
Bug 28172: Optimize Koha::Plugins::GetPlugins

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
Comment 4 David Nind 2022-11-01 00:05:39 UTC
The patch no longer applies :-(..
Comment 5 Fridolin Somers 2022-11-01 02:23:23 UTC
Arf not a trivial rebase.
I leave it to Julian ;)
Comment 6 Julian Maurice 2022-11-02 08:50:03 UTC
Created attachment 142917 [details] [review]
Bug 28172: [DO NOT PUSH] Test script for GetPlugins
Comment 7 Julian Maurice 2022-11-02 08:50:09 UTC
Created attachment 142918 [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 8 Julian Maurice 2022-11-02 08:57:08 UTC
Rebased on master, but now when running the test script I get a really bad time for "1000 calls to GetPlugins with all = 1".

As bug 29672 changes Koha::Plugins::call so that it does not use GetPlugins, I'm not sure if this patch is still relevant.
Comment 9 Katrin Fischer 2023-07-01 08:18:54 UTC
(In reply to Julian Maurice from comment #8)
> Rebased on master, but now when running the test script I get a really bad
> time for "1000 calls to GetPlugins with all = 1".
> 
> As bug 29672 changes Koha::Plugins::call so that it does not use GetPlugins,
> I'm not sure if this patch is still relevant.

Hi Julian, should we close this now that bug 29672 is pushed?
Comment 10 David Nind 2023-08-15 10:15:52 UTC
Changed status - fixed on bug 29672.