Bugzilla – Attachment 142920 Details for
Bug 29672
Increase performance of Koha::Plugins->call
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29672: Increase performance of Koha::Plugins->call
Bug-29672-Increase-performance-of-KohaPlugins-call.patch (text/plain), 4.53 KB, created by
Kyle M Hall (khall)
on 2022-11-02 11:17:30 UTC
(
hide
)
Description:
Bug 29672: Increase performance of Koha::Plugins->call
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2022-11-02 11:17:30 UTC
Size:
4.53 KB
patch
obsolete
>From a7c8306ce044b2a6e2064b3d865acd47e2679add Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 9 Dec 2021 14:49:32 +0100 >Subject: [PATCH] Bug 29672: Increase performance of Koha::Plugins->call > >Make use of Koha::Cache::Memory::Lite to avoid hitting the database and >creating plugins object for every call to Koha::Plugins->call > >Test plan: >1. Make sure plugins still work by executing > `prove t/db_dependent/Koha/Plugins/Plugins.t` >2. Run the test script provided in the following patch to see how it > affects performances > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/Plugins.pm | 61 +++++++++++++++++++++------ > t/db_dependent/Koha/Plugins/Plugins.t | 1 + > 2 files changed, 49 insertions(+), 13 deletions(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index f7b716638d..997d4a48b7 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -30,6 +30,7 @@ use Try::Tiny; > use C4::Context; > use C4::Output; > >+use Koha::Cache::Memory::Lite; > use Koha::Exceptions::Plugin; > use Koha::Plugins::Methods; > >@@ -74,25 +75,59 @@ updated by preceding plugins, provided that these plugins support that. > sub call { > my ($class, $method, @args) = @_; > >+ return unless C4::Context->config('enable_plugins'); >+ > my @responses; >- if (C4::Context->config('enable_plugins')) { >- my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method }); >- @plugins = grep { $_->can($method) } @plugins; >- # TODO: Remove warn when after_hold_create is removed from the codebase >- warn "after_hold_create is deprecated and will be removed soon. Contact the following plugin's authors: " . join( ', ', map {$_->{metadata}->{name}} @plugins) >- if $method eq 'after_hold_create' and @plugins; >- foreach my $plugin (@plugins) { >- my $response = eval { $plugin->$method(@args) }; >- if ($@) { >- warn sprintf("Plugin error (%s): %s", $plugin->get_metadata->{name}, $@); >+ my @plugins = $class->get_enabled_plugins(); >+ @plugins = grep { $_->can($method) } @plugins; >+ >+ # TODO: Remove warn when after_hold_create is removed from the codebase >+ warn "after_hold_create is deprecated and will be removed soon. Contact the following plugin's authors: " . join( ', ', map {$_->{metadata}->{name}} @plugins) >+ if $method eq 'after_hold_create' and @plugins; >+ >+ foreach my $plugin (@plugins) { >+ my $response = eval { $plugin->$method(@args) }; >+ if ($@) { >+ warn sprintf("Plugin error (%s): %s", $plugin->get_metadata->{name}, $@); >+ next; >+ } >+ >+ push @responses, $response; >+ } >+ >+ return @responses; >+} >+ >+sub get_enabled_plugins { >+ my ($class) = @_; >+ >+ return unless C4::Context->config('enable_plugins'); >+ >+ my $cache_key = 'enabled_plugins'; >+ my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache($cache_key); >+ unless ($enabled_plugins) { >+ $enabled_plugins = []; >+ my $rs = Koha::Database->schema->resultset('PluginData'); >+ $rs = $rs->search({ plugin_key => '__ENABLED__', plugin_value => 1 }); >+ my @plugin_classes = $rs->get_column('plugin_class')->all(); >+ foreach my $plugin_class (@plugin_classes) { >+ unless (can_load(modules => { $plugin_class => undef }, nocache => 1)) { >+ warn "Failed to load $plugin_class: $Module::Load::Conditional::ERROR"; > next; > } > >- push @responses, $response; >- } >+ my $plugin = eval { $plugin_class->new() }; >+ if ($@ || !$plugin) { >+ warn "Failed to instantiate plugin $plugin_class: $@"; >+ next; >+ } > >+ push @$enabled_plugins, $plugin; >+ } >+ Koha::Cache::Memory::Lite->set_in_cache($cache_key, $enabled_plugins); > } >- return @responses; >+ >+ return @$enabled_plugins; > } > > =head2 GetPlugins >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index 0360a8ab87..7d9166da9a 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -55,6 +55,7 @@ subtest 'call() tests' => sub { > $schema->storage->txn_begin; > # Temporarily remove any installed plugins data > Koha::Plugins::Methods->delete; >+ $schema->resultset('PluginData')->delete(); > > t::lib::Mocks::mock_config('enable_plugins', 1); > my $plugins = Koha::Plugins->new({ enable_plugins => 1 }); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29672
:
128376
|
128377
|
135660
|
135661
|
135704
|
142844
|
142845
|
142846
|
142916
|
142919
| 142920 |
142921
|
142922
|
142923