Bugzilla – Attachment 169234 Details for
Bug 37389
REST API queries joining on extended_attributes may cause severe performance issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37389: [SQUASH] Join alias fix
Bug-37389-SQUASH-Join-alias-fix.patch (text/plain), 4.57 KB, created by
Pedro Amorim
on 2024-07-19 14:35:35 UTC
(
hide
)
Description:
Bug 37389: [SQUASH] Join alias fix
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-07-19 14:35:35 UTC
Size:
4.57 KB
patch
obsolete
>From e3d23eb7fc99758c5e4ec962fab6810b325e4fbd Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Fri, 19 Jul 2024 14:31:58 +0000 >Subject: [PATCH] Bug 37389: [SQUASH] Join alias fix > >This is to be squashed into the previous patch, but I'm leaving an explanation here of this follow-up fix for now. >Only rename the join aliases if extended_attribute entry is a string 'type'. >If its an array, skip. >This 'array' method is used on the left-side search forms for ILL and patrons table. >Its the difference between > > [ > { > "extended_attributes.type": [ > "title", > "type", > "author", > "article_title", > "pages", > "issue", > "volume", > "year" > ], > "extended_attributes.value": { > "like": "%book%" > } > } > ] > >and > >[ > { > "extended_attributes.type": "year", > "extended_attributes.value": { > "like": "%book%" > } > } > ], > [ > { > "extended_attributes.type": "pages", > "extended_attributes.value": { > "like": "%book%" > } > } > ], > >Where the former searches for a single keyword occurrence in a potential list of extended_attributes and the latter allows for different keywords for each extended_attribute type (even though the datatable search input allows only for 1, this is utilized in other places such as ERM licenses additional fields and subscriptions searchable additional fields I believe). >--- > Koha/REST/Plugin/Query.pm | 25 +++++++++++++------------ > 1 file changed, 13 insertions(+), 12 deletions(-) > >diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm >index fd9dcf0482..aad5e4cde9 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -179,7 +179,7 @@ Generates the DBIC join attribute based on extended_attributes query entries, an > && reftype( $attributes->{prefetch} ) eq 'ARRAY' > && grep ( /extended_attributes/, @{ $attributes->{prefetch} } ) ) > { >- my @array = $self->_get_extended_attributes_entries( $filtered_params, 0 ); >+ my @array = $self->_get_extended_attributes_entries( $filtered_params ); > > # Calling our private method to build the extended attributes relations > my @joins = $result_set->_build_extended_attributes_relations(\@array); >@@ -559,7 +559,7 @@ Example: Returns 2 if given a $filtered_params containing the below: > =cut > > sub _get_extended_attributes_entries { >- my ( $self, $params, $extended_attributes_entries, @array ) = @_; >+ my ( $self, $params, @array ) = @_; > > if ( reftype($params) && reftype($params) eq 'HASH' ) { > >@@ -579,11 +579,11 @@ sub _get_extended_attributes_entries { > if $params->{'extended_attributes.type'}; > > foreach my $key ( keys %{$params} ) { >- return $self->_get_extended_attributes_entries( $params->{$key}, $extended_attributes_entries, @array ); >+ return $self->_get_extended_attributes_entries( $params->{$key}, @array ); > } > } elsif ( reftype($params) && reftype($params) eq 'ARRAY' ) { > foreach my $ea_instance (@$params) { >- @array = $self->_get_extended_attributes_entries( $ea_instance, $extended_attributes_entries, @array ); >+ @array = $self->_get_extended_attributes_entries( $ea_instance, @array ); > } > return @array; > } else { >@@ -628,15 +628,16 @@ It'll be rewritten as: > sub _rewrite_related_metadata_query { > my ( $params, $key, $value, @array ) = @_; > >- my $old_key_value = delete $params->{ 'extended_attributes.' . $key }; >- my $new_key_value = "extended_attributes_$old_key_value" . "." . $key; >- $params->{$new_key_value} = $old_key_value; >+ if(ref \$params->{ 'extended_attributes.' . $key } eq 'SCALAR' ){ >+ my $old_key_value = delete $params->{ 'extended_attributes.' . $key }; >+ my $new_key_value = "extended_attributes_$old_key_value" . "." . $key; >+ $params->{$new_key_value} = $old_key_value; > >- my $old_value_value = delete $params->{ 'extended_attributes.' . $value }; >- my $new_value_value = "extended_attributes_$old_key_value" . "." . $value; >- $params->{$new_value_value} = $old_value_value; >- >- push @array, $old_key_value; >+ my $old_value_value = delete $params->{ 'extended_attributes.' . $value }; >+ my $new_value_value = "extended_attributes_$old_key_value" . "." . $value; >+ $params->{$new_value_value} = $old_value_value; >+ push @array, $old_key_value; >+ } > > return @array; > } >-- >2.39.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 37389
:
169130
|
169133
|
169140
|
169149
|
169159
|
169178
|
169185
|
169189
|
169191
|
169192
|
169234
|
169243
|
169244
|
169245
|
169246
|
169317
|
169318
|
169569
|
169570
|
169583
|
169584
|
169585
|
169586
|
169850
|
169851
|
169944
|
169945
|
169946
|
169954
|
169955
|
169956