From 97d622bbcf8b212156bdcf7644f23f8f2d4fde30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Thu, 1 Sep 2022 19:45:25 +0000 Subject: [PATCH] Bug 31455: (QA follow-up) Make table creation O(N) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can insert the indices before the main loop to a hash, this way we don't have to look up during each loop iteration the index from an array which in the worst case might take O(N) thus making the total time complexity O(N^2). Signed-off-by: Joonas Kylmälä --- Koha/UI/Table/Builder/Items.pm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Koha/UI/Table/Builder/Items.pm b/Koha/UI/Table/Builder/Items.pm index 34b3cfcffd..615d210871 100644 --- a/Koha/UI/Table/Builder/Items.pm +++ b/Koha/UI/Table/Builder/Items.pm @@ -19,7 +19,6 @@ use Modern::Perl; use List::MoreUtils qw( uniq ); use C4::Biblio qw( GetMarcStructure GetMarcFromKohaField IsMarcStructureInternal ); use Koha::Items; -use List::MoreUtils qw(first_index); =head1 NAME @@ -72,16 +71,15 @@ Use it with: sub build_table { my ( $self, $params ) = @_; - my @itemnumbers = @{ $self->{itemnumbers} }; + my %itemnumbers_to_idx = map { $self->{itemnumbers}->[$_] => $_ } 0..$#{$self->{itemnumbers}}; my $items = Koha::Items->search( { itemnumber => $self->{itemnumbers} } ); my @items; while ( my $item = $items->next ) { my $item_info = $item->columns_to_str; - my $index = first_index { $_ eq $item->itemnumber } @itemnumbers; $item_info = { %$item_info, - index => $index, + index => $itemnumbers_to_idx{$item->itemnumber}, biblio => $item->biblio, safe_to_delete => $item->safe_to_delete, holds => $item->biblio->holds->count, -- 2.30.2