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

(-)a/C4/Reserves.pm (-1 / +12 lines)
Lines 1225-1231 and canreservefromotherbranches. Link Here
1225
=cut
1225
=cut
1226
1226
1227
sub IsAvailableForItemLevelRequest {
1227
sub IsAvailableForItemLevelRequest {
1228
    my ( $item, $patron, $pickup_branchcode ) = @_;
1228
    my $item                = shift;
1229
    my $patron              = shift;
1230
    my $pickup_branchcode   = shift;
1231
    # items_any_available is precalculated status passed from request.pl when set of items
1232
    # looped outside of IsAvailableForItemLevelRequest to avoid nested loops:
1233
    my $items_any_available = shift;
1229
1234
1230
    my $dbh = C4::Context->dbh;
1235
    my $dbh = C4::Context->dbh;
1231
    # must check the notforloan setting of the itemtype
1236
    # must check the notforloan setting of the itemtype
Lines 1260-1265 sub IsAvailableForItemLevelRequest { Link Here
1260
    if ( $on_shelf_holds == 1 ) {
1265
    if ( $on_shelf_holds == 1 ) {
1261
        return 1;
1266
        return 1;
1262
    } elsif ( $on_shelf_holds == 2 ) {
1267
    } elsif ( $on_shelf_holds == 2 ) {
1268
1269
        # if we have this param predefined from outer caller sub, we just need
1270
        # to return it, so we saving from having loop inside other loop:
1271
        return  $items_any_available ? 0 : 1
1272
            if defined $items_any_available;
1273
1263
        my $any_available = ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron });
1274
        my $any_available = ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron });
1264
        return $any_available ? 0 : 1;
1275
        return $any_available ? 0 : 1;
1265
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1276
    } 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 445-450 foreach my $biblionumber (@biblionumbers) { Link Here
445
                $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
445
                $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
446
        }
446
        }
447
447
448
        # iterating through all items first to check if any of them available
449
        # to pass this value further inside down to IsAvailableForItemLevelRequest to
450
        # it's complicated logic to analyse.
451
        # (before this loop was inside that sub loop so it was O(n^2) )
452
        my $items_any_available;
453
454
        $items_any_available = ItemsAnyAvailableForHold( { biblionumber => $biblioitemnumber, patron => $patron })
455
            if $patron;
456
448
        foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
457
        foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
449
            my $item = $iteminfos_of->{$itemnumber};
458
            my $item = $iteminfos_of->{$itemnumber};
450
            my $do_check;
459
            my $do_check;
Lines 558-564 foreach my $biblionumber (@biblionumbers) { Link Here
558
                       !$item->{cantreserve}
567
                       !$item->{cantreserve}
559
                    && !$exceeded_maxreserves
568
                    && !$exceeded_maxreserves
560
                    && $can_item_be_reserved eq 'OK'
569
                    && $can_item_be_reserved eq 'OK'
561
                    && IsAvailableForItemLevelRequest($item_object, $patron)
570
                    # items_any_available defined outside of the current loop,
571
                    # so we avoiding loop inside IsAvailableForItemLevelRequest:
572
                    && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
562
                  )
573
                  )
563
                {
574
                {
564
                    $item->{available} = 1;
575
                    $item->{available} = 1;
565
- 

Return to bug 24185