From e313bcf1303a7c334327b37e1e8a629ffb2e0005 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 7 Oct 2020 18:33:59 +0200 Subject: [PATCH] Bug 24488: [DISCUSSION] For comparaison I'd like someone to run a benchmark with and without this patch on a quite big database and see which approach is the best Signed-off-by: Michal Denar Signed-off-by: Josef Moravec Signed-off-by: Michal Denar Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- circ/pendingreserves.pl | 88 +++---------------- .../prog/en/modules/circ/pendingreserves.tt | 26 +++--- 2 files changed, 26 insertions(+), 88 deletions(-) diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 554c8cb9eb..8c58ee18fb 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -205,7 +205,7 @@ foreach my $bibnum ( @biblionumbers ){ my @branchtransfers = map { $_->itemnumber } Koha::Item::Transfers->search({ datearrived => undef }, { columns => [ 'itemnumber' ], collapse => 1 }); my @issues = map { $_->itemnumber } Koha::Checkouts->search({}, { columns => [ 'itemnumber' ], collapse => 1 }); - my $items = Koha::Items->search( + @items = Koha::Items->search( { biblionumber => $bibnum, itemlost => 0, @@ -216,101 +216,39 @@ foreach my $bibnum ( @biblionumbers ){ ); # get available item types for each biblio - my $res_itemtypes; + my @res_itemtypes; if ( C4::Context->preference('item-level_itypes') ){ - $res_itemtypes = $items->search( - { - itype => { '!=', undef }, - }, - { - columns => 'itype', - distinct => 1, - } - ); + @res_itemtypes = uniq map { defined $_->itype ? $_->itype : () } @items; } else { - my $res_itemtypes = Koha::Biblioitems->search( + @res_itemtypes = Koha::Biblioitems->search( { biblionumber => $bibnum, itemtype => { '!=', undef } }, { columns => 'itemtype', distinct => 1, } - ); + )->get_column('itemtype'); } - $reserves->{$bibnum}->{itemtypes} = $res_itemtypes; + $reserves->{$bibnum}->{itemtypes} = \@res_itemtypes; # get available locations for each biblio - my $res_locations = $items->search( - { - location => { '!=', undef }, - }, - { - columns => 'location', - distinct => 1, - } - ); - $reserves->{$bibnum}->{locations} = $res_locations; + $reserves->{$bibnum}->{locations} = [ uniq map { defined $_->location ? $_->location : () } @items ]; # get available callnumbers for each biblio - my $res_callnumbers = $items->search( - { - itemcallnumber => { '!=', undef }, - }, - { - columns => 'itemcallnumber', - distinct => 1, - } - ); - $reserves->{$bibnum}->{callnumbers} = $res_callnumbers; + $reserves->{$bibnum}->{locations} = [ uniq map { defined $_->itemcallnumber ? $_->itemcallnumber : () } @items ]; # get available enumchrons for each biblio - my $res_enumchrons = $items->search( - { - enumchron => { '!=', undef }, - }, - { - columns => 'enumchron', - distinct => 1, - } - ); - $reserves->{$bibnum}->{enumchrons} = $res_enumchrons; + $reserves->{$bibnum}->{enumchrons} = [ uniq map { defined $_->enumchron ? $_->enumchron : () } @items ]; # get available copynumbers for each biblio - my $res_copynumbers = $items->search( - { - copynumber => { '!=', undef }, - }, - { - columns => 'copynumber', - distinct => 1, - } - ); - $reserves->{$bibnum}->{copynumbers} = $res_copynumbers; + $reserves->{$bibnum}->{copynumbers} = [ uniq map { defined $_->copynumber ? $_->copynumber : () } @items ]; # get available barcodes for each biblio - my $res_barcodes = $items->search( - { - barcode => { '!=', undef }, - }, - { - columns => 'barcode', - distinct => 1, - } - ); - $reserves->{$bibnum}->{barcodes} = $res_barcodes; + $reserves->{$bibnum}->{barcodes} = [ uniq map { defined $_->barcode ? $_->barcode : () } @items ]; # get available holding branches for each biblio - my $res_holdingbranches = $items->search( - { - holdingbranch => { '!=', undef }, - }, - { - columns => 'holdingbranch', - distinct => 1, - } - ); - $reserves->{$bibnum}->{holdingbranches} = $res_holdingbranches; + $reserves->{$bibnum}->{holdingbranches} = [ uniq map { defined $_->holdingbranch ? $_->holdingbranch : () } @items ]; # items available - my $items_count = $items->count; + my $items_count = scalar @items; $reserves->{$bibnum}->{items_count} = $items_count; # patrons with holds diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt index fb0be90050..2046f45f2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt @@ -91,48 +91,48 @@ " [% END %] - [% IF ( reserve.value.holdingbranches ) %] + [% IF ( reserve.value.holdingbranches.size ) %]
    [% FOREACH holdingbranch IN reserve.value.holdingbranches %] -
  • [% Branches.GetName ( holdingbranch.holdingbranch ) | html %]
  • +
  • [% Branches.GetName ( holdingbranch ) | html %]
  • [% END %]
[% END %] - [% IF ( reserve.value.barcodes.count ) %] - [% SET barcode = reserve.value.barcodes.next.barcode %] + [% IF ( reserve.value.barcodes.size ) %] + [% SET barcode = reserve.value.barcodes.first %] [% IF ( reserve.value.itemnumber ) %]Only [% barcode | html %][% ELSE %][% barcode | html %] or any available.[% END %] [% END %] - [% IF ( reserve.value.callnumbers ) %] + [% IF ( reserve.value.callnumbers.size ) %]
    [% FOREACH callnumber IN reserve.value.callnumbers %]
  • - [% callnumber.itemcallnumber | html %] + [% callnumber | html %]
  • [% END %]
[% END %] - [% IF ( reserve.value.copynumbers ) %] + [% IF ( reserve.value.copynumbers.size ) %]
    [% FOREACH copyno IN reserve.value.copynumbers %]
  • - [% copyno.copynumber | html %] + [% copyno | html %]
  • [% END %]
[% END %] - [% IF ( reserve.value.enumchrons ) %] + [% IF ( reserve.value.enumchrons.size ) %]
    [% FOREACH enumchron IN reserve.value.enumchrons %]
  • - [% enumchron.enumchron | html %] + [% enumchron | html %]
  • [% END %]
@@ -142,9 +142,9 @@
    [% FOREACH type IN reserve.value.itemtypes %] [% IF Koha.Preference('item-level_itypes') %] -
  • [% ItemTypes.GetDescription( type.itype ) | html %]
  • +
  • [% ItemTypes.GetDescription( type ) | html %]
  • [% ELSE %] -
  • [% ItemTypes.GetDescription( type.itemtype ) | html %]
  • +
  • [% ItemTypes.GetDescription( type ) | html %]
  • [% END %] [% END %]
@@ -152,7 +152,7 @@
    [% FOREACH loc IN reserve.value.locations %] -
  • [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => loc.location) | html %]
  • +
  • [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => loc ) | html %]
  • [% END %]
-- 2.39.5