From 9ec37b260a0b60ef7092eb1c7a2079f726309215 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 11 Feb 2025 11:03:24 -0300 Subject: [PATCH] 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 --- Koha/ILL/Request.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm index 979b975368d..012252274dd 100644 --- a/Koha/ILL/Request.pm +++ b/Koha/ILL/Request.pm @@ -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 -- 2.49.0