Bug 31455: (QA follow-up) Make table creation O(N)

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ä <joonas.kylmala@iki.fi>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 223d9d3a99)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Joonas Kylmälä 2022-09-01 19:45:25 +00:00 committed by Lucas Gass
parent d8956d387d
commit b2a66cd307

View file

@ -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,