Bug 39092: Cache the plugin object when loading plugin backend

This patch makes the `load_backend()` method cache the plugin instance
object when calculated. This will reduce the calls in other places where
we query for the plugin.

It is also the excuse to add some tests for this methods which were
lacking.

To test:
1. Apply the unit tests
2. Run:
   $ ktd --shell
 k$ prove t/db_dependent/Koha/Plugins/ILL/Backends.t
=> FAIL: Tests fail, plugin instance caching is not happening
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Tomas Cohen Arazi 2025-02-11 11:03:24 -03:00 committed by Katrin Fischer
parent b914ace0b7
commit a3c8e710aa
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 4 additions and 3 deletions

View File

@ -484,15 +484,16 @@ sub load_backend {
};
# Find plugin implementing the backend for the request
my $backend_plugin = $self->get_backend_plugin($backend_name);
my $plugin = $self->get_backend_plugin($backend_name);
if ( $backend_name eq 'Standard' ) {
# Load the Standard core backend
$self->{_my_backend} = Koha::ILL::Backend::Standard->new($backend_params);
} elsif ($backend_plugin) {
} elsif ($plugin) {
$self->{_my_backend} = $backend_plugin->new_ill_backend($backend_params);
$self->{_my_backend} = $plugin->new_ill_backend($backend_params);
$self->{_plugin} = $plugin;
} elsif ($backend_name) {
# Fallback to loading through backend_dir config