Bugzilla – Attachment 163200 Details for
Bug 36277
t/db_dependent/api/v1/transfer_limits.t is failing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36277: Improve algorithmic complexity of batch_add
Bug-36277-Improve-algorithmic-complexity-of-batcha.patch (text/plain), 3.03 KB, created by
Tomás Cohen Arazi (tcohen)
on 2024-03-15 11:03:28 UTC
(
hide
)
Description:
Bug 36277: Improve algorithmic complexity of batch_add
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2024-03-15 11:03:28 UTC
Size:
3.03 KB
patch
obsolete
>From 16ed7e1eb291c06f00eb18d595b77d5b3c0cdb22 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 14 Mar 2024 14:39:56 +0100 >Subject: [PATCH] Bug 36277: Improve algorithmic complexity of batch_add > >The 2 nested loops are terrible in term of algorithmic complexity. >Especially if we are fetching from there. > >The goal of this patch is to fetch all the limits outside of the loop. > >If you have 100 libraries, it will remove 100^2 - 1 fetches! > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/REST/V1/TransferLimits.pm | 33 ++++++++++++++++++++------------- > 1 file changed, 20 insertions(+), 13 deletions(-) > >diff --git a/Koha/REST/V1/TransferLimits.pm b/Koha/REST/V1/TransferLimits.pm >index 83fa6c568d4..cba63776c1d 100644 >--- a/Koha/REST/V1/TransferLimits.pm >+++ b/Koha/REST/V1/TransferLimits.pm >@@ -141,32 +141,39 @@ sub batch_add { > @to_branches = @library_ids unless $params->{to_library_id}; > } > >+ my $dbic_params = Koha::Item::Transfer::Limits->new->attributes_from_api($params); >+ my %existing_limits = >+ map { sprintf( "%s:%s:%s:%s", $_->fromBranch, $_->toBranch, $_->itemtype, $_->ccode ) => 1 } >+ Koha::Item::Transfer::Limits->search($dbic_params)->as_list; >+ > my @results; >- foreach my $from ( @from_branches ) { >- foreach my $to ( @to_branches ) { >- my $limit_params = { %$params }; >+ foreach my $from (@from_branches) { >+ foreach my $to (@to_branches) { >+ my $limit_params = {%$params}; > > $limit_params->{from_library_id} = $from; >- $limit_params->{to_library_id} = $to; >+ $limit_params->{to_library_id} = $to; > > next if $to eq $from; > >- my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $limit_params ); >- my $exists = Koha::Item::Transfer::Limits->search( $transfer_limit->unblessed )->count; >- unless ( $exists ) { >- $transfer_limit->store; >- push( @results, $transfer_limit->to_api()); >- } >+ my $key = sprintf( >+ "%s:%s:%s:%s", $limit_params->{from_branch_id} || q{}, >+ $limit_params->{to_branch_id} || q{}, $limit_params->{item_type} || q{}, >+ $limit_params->{collection_code} || q{} >+ ); >+ next if exists $existing_limits{$key}; >+ >+ my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api($limit_params); >+ $transfer_limit->store; >+ push( @results, $transfer_limit->to_api() ); > } > } >- my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $params ); > > return $c->render( > status => 201, > openapi => \@results > ); >- } >- catch { >+ } catch { > $c->unhandled_exception($_); > }; > } >-- >2.44.0
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 36277
:
163134
|
163135
|
163189
|
163190
|
163199
| 163200 |
163225