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:
parent
d8956d387d
commit
b2a66cd307
1 changed files with 2 additions and 4 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue