From: Mike Rylander Date: Tue, 20 Mar 2012 17:02:46 +0000 (-0400) Subject: Loop through holds beyond the first 10 in cases where the front of the list is disqua... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fmiker%2FLP960369_try_harder_to_find_a_hold;p=working%2FEvergreen.git Loop through holds beyond the first 10 in cases where the front of the list is disqualified Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index 5c840c5d10..77283d8237 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -2884,57 +2884,61 @@ sub find_nearest_permitted_hold { my $fifo = $U->ou_ancestor_setting_value($user->ws_ou, 'circ.holds_fifo'); # search for what should be the best holds for this copy to fulfill - my $best_holds = $U->storagereq( - "open-ils.storage.action.hold_request.nearest_hold.atomic", - $user->ws_ou, $copy->id, 10, $hold_stall_interval, $fifo ); - - unless(@$best_holds) { - - if( my $hold = $$old_holds[0] ) { - $logger->info("circulator: using existing pre-targeted hold ".$hold->id." in hold search"); - return ($hold); - } - - $logger->info("circulator: no suitable holds found for copy $bc"); - return (undef, $evt); - } - - + my $offset = 0; my $best_hold; + my $found_none; + until ($best_hold) { - # for each potential hold, we have to run the permit script - # to make sure the hold is actually permitted. - my %reqr_cache; - my %org_cache; - for my $holdid (@$best_holds) { - next unless $holdid; - $logger->info("circulator: checking if hold $holdid is permitted for copy $bc"); - - my $hold = $editor->retrieve_action_hold_request($holdid) or next; - my $reqr = $reqr_cache{$hold->requestor} || $editor->retrieve_actor_user($hold->requestor); - my $rlib = $org_cache{$hold->request_lib} || $editor->retrieve_actor_org_unit($hold->request_lib); - - $reqr_cache{$hold->requestor} = $reqr; - $org_cache{$hold->request_lib} = $rlib; - - # see if this hold is permitted - my $permitted = OpenILS::Utils::PermitHold::permit_copy_hold( - { patron_id => $hold->usr, - requestor => $reqr, - copy => $copy, - pickup_lib => $hold->pickup_lib, - request_lib => $rlib, - retarget => 1 - } - ); + my $best_holds = $U->storagereq( + "open-ils.storage.action.hold_request.nearest_hold.atomic", + $user->ws_ou, $copy->id, 10, $hold_stall_interval, $fifo, $offset ); + + $offest += 10; - if( $permitted ) { - $best_hold = $hold; - last; + unless(@$best_holds) { + + if( my $hold = $$old_holds[0] ) { + $logger->info("circulator: using existing pre-targeted hold ".$hold->id." in hold search"); + return ($hold); + } + + $logger->info("circulator: no suitable holds found for copy $bc"); + return (undef, $evt); + } + + # for each potential hold, we have to run the permit script + # to make sure the hold is actually permitted. + my %reqr_cache; + my %org_cache; + for my $holdid (@$best_holds) { + next unless $holdid; + $logger->info("circulator: checking if hold $holdid is permitted for copy $bc"); + + my $hold = $editor->retrieve_action_hold_request($holdid) or next; + my $reqr = $reqr_cache{$hold->requestor} || $editor->retrieve_actor_user($hold->requestor); + my $rlib = $org_cache{$hold->request_lib} || $editor->retrieve_actor_org_unit($hold->request_lib); + + $reqr_cache{$hold->requestor} = $reqr; + $org_cache{$hold->request_lib} = $rlib; + + # see if this hold is permitted + my $permitted = OpenILS::Utils::PermitHold::permit_copy_hold( + { patron_id => $hold->usr, + requestor => $reqr, + copy => $copy, + pickup_lib => $hold->pickup_lib, + request_lib => $rlib, + retarget => 1 + } + ); + + if( $permitted ) { + $best_hold = $hold; + last; + } } } - unless( $best_hold ) { # no "good" permitted holds were found if( my $hold = $$old_holds[0] ) { # can we return a pre-targeted hold? $logger->info("circulator: using existing pre-targeted hold ".$hold->id." in hold search"); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm index f6a4515a2d..38a76db0b8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm @@ -287,6 +287,7 @@ sub nearest_hold { my $limit = int(shift()) || 10; my $age = shift() || '0 seconds'; my $fifo = shift(); + my $offset = shift() || '0'; local $OpenILS::Application::Storage::WRITE = 1; @@ -309,6 +310,7 @@ sub nearest_hold { AND h.frozen IS FALSE ORDER BY CASE WHEN h.hold_type IN ('R','F') THEN 0 ELSE 1 END, $holdsort LIMIT $limit + OFFSET $offset SQL $client->respond( $_ ) for ( @$ids );