improve hold targetting
authorgmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 24 Sep 2010 16:37:23 +0000 (16:37 +0000)
committergmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 24 Sep 2010 16:37:23 +0000 (16:37 +0000)
* all potential capturable copies are now checked (up to the first
  one that is permitted for the request), instead of a small random
  subset of them
* don't do redundant permission checks

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

git-svn-id: svn://svn.open-ils.org/ILS/trunk@17954 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm

index 471adc8..782eaff 100644 (file)
@@ -1868,17 +1868,19 @@ sub choose_nearest_copy {
                next unless (@capturable);
 
                my $rand = int(rand(scalar(@capturable)));
-               while (my ($c) = splice(@capturable,$rand)) {
-                       return $c if ( OpenILS::Utils::PermitHold::permit_copy_hold(
+               my %seen = ();
+               while (my ($c) = splice(@capturable, $rand, 1)) {
+                       return $c if !exists($seen{$c->id}) && ( OpenILS::Utils::PermitHold::permit_copy_hold(
                                { title => $c->call_number->record->to_fieldmapper,
                                  title_descriptor => $c->call_number->record->record_descriptor->next->to_fieldmapper,
                                  patron => $hold->usr->to_fieldmapper,
                                  copy => $c->to_fieldmapper,
                                  requestor => $hold->requestor->to_fieldmapper,
                                  request_lib => $hold->request_lib->to_fieldmapper,
-                                  pickup_lib => $hold->pickup_lib->id,
+                                 pickup_lib => $hold->pickup_lib->id,
                                }
                        ));
+                       $seen{$c->id}++;
 
                        last unless(@capturable);
                        $rand = int(rand(scalar(@capturable)));