View | Details | Raw Unified | Return to bug 24185
Collapse All | Expand All

(-)a/C4/Reserves.pm (-1 / +12 lines)
Lines 1204-1210 and canreservefromotherbranches. Link Here
1204
=cut
1204
=cut
1205
1205
1206
sub IsAvailableForItemLevelRequest {
1206
sub IsAvailableForItemLevelRequest {
1207
    my ( $item, $patron, $pickup_branchcode ) = @_;
1207
    my $item                = shift;
1208
    my $patron              = shift;
1209
    my $pickup_branchcode   = shift;
1210
    # items_any_available is precalculated status passed from request.pl when set of items
1211
    # looped outside of IsAvailableForItemLevelRequest to avoid nested loops:
1212
    my $items_any_available = shift;
1208
1213
1209
    my $dbh = C4::Context->dbh;
1214
    my $dbh = C4::Context->dbh;
1210
    # must check the notforloan setting of the itemtype
1215
    # must check the notforloan setting of the itemtype
Lines 1239-1244 sub IsAvailableForItemLevelRequest { Link Here
1239
    if ( $on_shelf_holds == 1 ) {
1244
    if ( $on_shelf_holds == 1 ) {
1240
        return 1;
1245
        return 1;
1241
    } elsif ( $on_shelf_holds == 2 ) {
1246
    } elsif ( $on_shelf_holds == 2 ) {
1247
1248
        # if we have this param predefined from outer caller sub, we just need
1249
        # to return it, so we saving from having loop inside other loop:
1250
        return  $items_any_available ? 0 : 1
1251
            if defined $items_any_available;
1252
1242
        my $any_available = ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron });
1253
        my $any_available = ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron });
1243
        return $any_available ? 0 : 1;
1254
        return $any_available ? 0 : 1;
1244
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1255
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
(-)a/reserve/request.pl (-2 / +12 lines)
Lines 444-449 foreach my $biblionumber (@biblionumbers) { Link Here
444
                $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
444
                $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
445
        }
445
        }
446
446
447
        # iterating through all items first to check if any of them available
448
        # to pass this value further inside down to IsAvailableForItemLevelRequest to
449
        # it's complicated logic to analyse.
450
        # (before this loop was inside that sub loop so it was O(n^2) )
451
        my $items_any_available;
452
453
        $items_any_available = ItemsAnyAvailableForHold( { biblionumber => $biblioitemnumber, patron => $patron })
454
            if $patron;
455
447
        foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
456
        foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
448
            my $item = $iteminfos_of->{$itemnumber};
457
            my $item = $iteminfos_of->{$itemnumber};
449
            my $do_check;
458
            my $do_check;
Lines 557-563 foreach my $biblionumber (@biblionumbers) { Link Here
557
                       !$item->{cantreserve}
566
                       !$item->{cantreserve}
558
                    && !$exceeded_maxreserves
567
                    && !$exceeded_maxreserves
559
                    && $can_item_be_reserved eq 'OK'
568
                    && $can_item_be_reserved eq 'OK'
560
                    && IsAvailableForItemLevelRequest($item_object, $patron)
569
                    # items_any_available defined outside of the current loop,
570
                    # so we avoiding loop inside IsAvailableForItemLevelRequest:
571
                    && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
561
                  )
572
                  )
562
                {
573
                {
563
                    $item->{available} = 1;
574
                    $item->{available} = 1;
564
- 

Return to bug 24185