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

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2025-09-22 16:24:54 -03:00 committed by Lucas Gass
parent 633f84b57b
commit aa20cb9346
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 11 additions and 8 deletions

View File

@ -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;
}