From 62851a8e09c27b8ca3c9c1b126c4f321bf4c8cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Mon, 22 Sep 2025 16:24:54 -0300 Subject: [PATCH] Bug 40856: Optimize Standard backend metadata method with database-level filtering This patch optimizes the metadata() method in the Standard ILL backend to use database-level filtering instead of inefficient linear searches. Performance improvement: - Before: Load all attributes, then filter each with linear search - After: Load only relevant attributes using database index Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/ILL/Backend/Standard.t => SUCCESS: Tests pass! Optimization maintains compatibility 3. Test ILL request metadata display: - View ILL request details - Verify metadata shows correctly - Check ignored fields are excluded => SUCCESS: Same functionality, better performance 4. Sign off :-D --- Koha/ILL/Backend/Standard.pm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Koha/ILL/Backend/Standard.pm b/Koha/ILL/Backend/Standard.pm index 4aaff4641d..65f332b86b 100644 --- a/Koha/ILL/Backend/Standard.pm +++ b/Koha/ILL/Backend/Standard.pm @@ -145,21 +145,24 @@ that we do not consider to be metadata sub metadata { my ( $self, $request ) = @_; - my $attrs = $request->extended_attributes; - my $metadata = {}; - my @ignore = ( + + my @ignore = ( 'requested_partners', 'type', 'type_disclaimer_value', 'type_disclaimer_date', 'unauthenticated_first_name', 'unauthenticated_last_name', 'unauthenticated_email', 'historycheck_requests', 'copyrightclearance_confirmed' ); + + # Use database-level filtering instead of manual iteration + my $attrs = $request->extended_attributes->search( { type => { '-not_in' => \@ignore } } ); + my $core_fields = _get_core_fields(); + my $metadata = {}; + while ( my $attr = $attrs->next ) { my $type = $attr->type; - if ( !grep { $_ eq $type } @ignore ) { - my $name; - $name = $core_fields->{$type} || ucfirst($type); - $metadata->{$name} = $attr->value; - } + my $name = $core_fields->{$type} || ucfirst($type); + $metadata->{$name} = $attr->value; } + return $metadata; } -- 2.51.0