Bugzilla – Attachment 169954 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: Add tests
Bug-37389-Add-tests.patch (text/plain), 9.93 KB, created by
Pedro Amorim
on 2024-08-01 16:25:28 UTC
(
hide
)
Description:
Bug 37389: Add tests
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-08-01 16:25:28 UTC
Size:
9.93 KB
patch
obsolete
>From 33ba4629b30fda27b9631115f48b10c53e0d3834 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Thu, 25 Jul 2024 15:27:42 +0000 >Subject: [PATCH] Bug 37389: Add tests > >prove t/Koha/REST/Plugin/Query.t >prove t/db_dependent/Koha/Objects/Mixin/ExtendedAttributes.t > >Co-authored-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/Koha/REST/Plugin/Query.t | 71 ++++++- > .../Koha/Objects/Mixin/ExtendedAttributes.t | 189 ++++++++++++++++++ > 2 files changed, 255 insertions(+), 5 deletions(-) > create mode 100644 t/db_dependent/Koha/Objects/Mixin/ExtendedAttributes.t > >diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t >index 8e4178be33..ac5a803a9b 100755 >--- a/t/Koha/REST/Plugin/Query.t >+++ b/t/Koha/REST/Plugin/Query.t >@@ -331,12 +331,35 @@ get '/dbic_extended_attributes_join' => sub { > ]; > my $attributes = { 'prefetch' => ['extended_attributes'] }; > >- $c->dbic_extended_attributes_join( >+ my $result_set = Koha::Patrons->new; >+ >+ $c->render( json => { 'attributes' => $attributes, 'filtered_params' => $filtered_params }, status => 200 ); >+}; >+ >+get '/dbic_extended_attributes_join_multiple_values' => sub { >+ my ( $c, $args ) = @_; >+ >+ my $filtered_params = [ > { >- 'filtered_params' => $filtered_params, >- 'attributes' => $attributes >+ '-and' => [ >+ [ >+ { >+ 'extended_attributes.attribute' => { 'like' => 'abc%' }, >+ 'extended_attributes.code' => 'CODE_1' >+ } >+ ], >+ [ >+ { >+ 'extended_attributes.code' => 'CODE_2', >+ 'extended_attributes.attribute' => { 'like' => '123%' } >+ } >+ ] >+ ] > } >- ); >+ ]; >+ my $attributes = { 'prefetch' => ['extended_attributes'] }; >+ >+ my $result_set = Koha::Patrons->new; > > $c->render( json => { 'attributes' => $attributes, 'filtered_params' => $filtered_params }, status => 200 ); > }; >@@ -350,7 +373,7 @@ sub to_model { > > # The tests > >-use Test::More tests => 9; >+use Test::More tests => 10; > use Test::Mojo; > > subtest 'extract_reserved_params() tests' => sub { >@@ -684,5 +707,43 @@ subtest 'dbic_validate_operators' => sub { > # Invalid queries > $q = [ { "-and" => [ [ { "biblio_id" => { "like(sleep(1/100000))or" => "%a%" } } ] ] } ]; > $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(400); >+}; > >+subtest 'dbic_extended_attributes_join() tests' => sub { >+ >+ plan tests => 4; >+ >+ my $t = Test::Mojo->new; >+ >+ $t->get_ok( '/dbic_extended_attributes_join_multiple_values' => { 'x-koha-embed' => 'extended_attributes' } ) >+ ->json_has( >+ '/attributes' => { >+ 'join' => [ >+ 'extended_attributes_CODE_1', >+ 'extended_attributes_CODE_2' >+ ], >+ 'prefetch' => ['extended_attributes'] >+ } >+ ); >+ >+ $t->get_ok( '/dbic_extended_attributes_join' => { 'x-koha-embed' => 'extended_attributes' } )->json_has( >+ '/filtered_params' => [ >+ { >+ '-and' => [ >+ [ >+ { >+ 'extended_attributes_CODE_1.code' => 'CODE_1', >+ 'extended_attributes_CODE_1.attribute' => { 'like' => 'abc%' } >+ } >+ ], >+ [ >+ { >+ 'extended_attributes_CODE_2.code' => 'CODE_2', >+ 'extended_attributes_CODE_2.attribute' => { 'like' => 'abc%' } >+ } >+ ], >+ ] >+ } >+ ] >+ ); > }; >diff --git a/t/db_dependent/Koha/Objects/Mixin/ExtendedAttributes.t b/t/db_dependent/Koha/Objects/Mixin/ExtendedAttributes.t >new file mode 100644 >index 0000000000..6d84c4c0cf >--- /dev/null >+++ b/t/db_dependent/Koha/Objects/Mixin/ExtendedAttributes.t >@@ -0,0 +1,189 @@ >+#!/usr/bin/perl >+ >+# Copyright 2024 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use C4::Context; >+ >+use Koha::Database; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'extended_attributes patrons join searches() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $builder = t::lib::TestBuilder->new; >+ >+ my $patron1 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ my $patron2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ >+ my $attribute_type_1 = $builder->build( >+ { >+ source => 'BorrowerAttributeType', >+ value => { repeatable => 1, is_date => 0, code => 'CODE_1' }, >+ } >+ ); >+ my $attribute_type_2 = $builder->build( >+ { >+ source => 'BorrowerAttributeType', >+ value => { repeatable => 1, is_date => 0, code => 'CODE_2' } >+ } >+ ); >+ >+ my $attr1 = Koha::Patron::Attribute->new( >+ { >+ borrowernumber => $patron1, >+ code => $attribute_type_1->{code}, >+ attribute => 'Bar' >+ } >+ )->store; >+ my $attr2 = Koha::Patron::Attribute->new( >+ { >+ borrowernumber => $patron1, >+ code => $attribute_type_2->{code}, >+ attribute => 'Foo' >+ } >+ )->store; >+ >+ my $patrons_search = Koha::Patrons->search( >+ [ >+ '-and'=>[ >+ { >+ 'extended_attributes.attribute' => { 'like' => '%Bar%' }, >+ 'extended_attributes.code' => $attr1->code >+ }, >+ { >+ 'extended_attributes.attribute' => { 'like' => '%Foo%' }, >+ 'extended_attributes.code' => $attr2->code >+ } >+ ], >+ ], >+ { 'prefetch' => ['extended_attributes'] } >+ ); >+ >+ is( $patrons_search->count, 1, "Patrons extended_attribute 'AND' query works." ); >+ >+ my $patrons_search2 = Koha::Patrons->search( >+ [ >+ '-and' => [ >+ { >+ 'extended_attributes.attribute' => { 'like' => '%Bar%' }, >+ 'extended_attributes.code' => $attr1->code >+ }, >+ { >+ 'extended_attributes.attribute' => { 'like' => '%Bar%' }, >+ 'extended_attributes.code' => $attr2->code >+ } >+ ], >+ ], >+ { 'prefetch' => ['extended_attributes'] } >+ ); >+ >+ is( $patrons_search2->count, 0, "Second patrons extended_attribute 'AND' query works." ); >+ >+ >+ my $patrons_search3 = Koha::Patrons->search( >+ [ >+ [ >+ { >+ 'extended_attributes.attribute' => { 'like' => '%Bar%' }, >+ 'extended_attributes.code' => $attr1->code >+ } >+ ], >+ [ >+ { >+ 'extended_attributes.attribute' => { 'like' => '%Foo%' }, >+ 'extended_attributes.code' => $attr2->code >+ } >+ ], >+ [ >+ { >+ 'extended_attributes.attribute' => { 'like' => '%Foo%' }, >+ 'extended_attributes.code' => $attr1->code >+ } >+ ], >+ ], >+ { 'prefetch' => ['extended_attributes'] } >+ ); >+ >+ is( $patrons_search3->count, 1, "Patrons extended_attribute 'OR' search works" ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'extended_attributes ill requests join searches() tests' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $builder = t::lib::TestBuilder->new; >+ >+ # ILL::Requests >+ my $illrequest1 = $builder->build( { source => 'Illrequest' } )->{illrequest_id}; >+ my $illrequest2 = $builder->build( { source => 'Illrequest' } )->{illrequest_id}; >+ >+ my $illrequest_attribute1 = 'author'; >+ >+ my $ill_attr1 = Koha::ILL::Request::Attribute->new( >+ { >+ illrequest_id => $illrequest1, >+ type => 'author', >+ value => 'Pedro' >+ } >+ )->store; >+ my $ill_attr2 = Koha::ILL::Request::Attribute->new( >+ { >+ illrequest_id => $illrequest2, >+ type => 'author', >+ value => 'Pedro' >+ } >+ )->store; >+ >+ my $ill_requests = Koha::ILL::Requests->search( >+ [ >+ [ >+ { >+ 'extended_attributes.value' => { 'like' => '%Pedro%' }, >+ 'extended_attributes.type' => $illrequest_attribute1 >+ } >+ ], >+ [ >+ { >+ 'extended_attributes.value' => { 'like' => '%field2 value%' }, >+ 'extended_attributes.type' => $illrequest_attribute1 >+ } >+ ], >+ ], >+ { 'prefetch' => ['extended_attributes'] } >+ ); >+ >+ is( $ill_requests->count, 2, "ILL requests extended_attribute search works" ); >+ >+ $schema->storage->txn_rollback; >+ >+}; >-- >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