From fa0665ad92ac9d69d7ffde4158870f805619c413 Mon Sep 17 00:00:00 2001 From: =?utf8?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=utf8 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ä Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 223d9d3a99903cff3d8a3078e6921da79099375c) Signed-off-by: Lucas Gass (cherry picked from commit b2a66cd3075b85a388272885048ba3248ce60500) Signed-off-by: Arthur Suzuki --- Koha/UI/Table/Builder/Items.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Koha/UI/Table/Builder/Items.pm b/Koha/UI/Table/Builder/Items.pm index 516414d264..3cfaed3578 100644 --- a/Koha/UI/Table/Builder/Items.pm +++ b/Koha/UI/Table/Builder/Items.pm @@ -71,7 +71,7 @@ Use it with: sub build_table { my ( $self, $params ) = @_; - + my %itemnumbers_to_idx = map { $self->{itemnumbers}->[$_] => $_ } 0..$#{$self->{itemnumbers}}; my $items = Koha::Items->search( { itemnumber => $self->{itemnumbers} } ); my @items; @@ -79,6 +79,7 @@ sub build_table { my $item_info = $item->columns_to_str; $item_info = { %$item_info, + index => $itemnumbers_to_idx{$item->itemnumber}, biblio => $item->biblio, safe_to_delete => $item->safe_to_delete, holds => $item->biblio->holds->count, -- 2.39.5