improving "nearest_hold"
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 27 Jul 2006 17:58:59 +0000 (17:58 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 27 Jul 2006 17:58:59 +0000 (17:58 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5129 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 33dd5cd..1386f5d 100644 (file)
@@ -162,23 +162,27 @@ sub nearest_hold {
        my $client = shift;
        my $pl = shift;
        my $cp = shift;
+       my $limit = int(shift()) || 10;
 
-       my ($id) = action::hold_request->db_Main->selectrow_array(<<"   SQL", {}, $pl,$cp);
+       my ($id) = action::hold_request->db_Main->selectrow_array(<<"   SQL", {}, $cp, $pl);
                SELECT  h.id
                  FROM  action.hold_request h
                        JOIN action.hold_copy_map hm ON (hm.hold = h.id)
-                 WHERE h.pickup_lib = ?
-                       AND hm.target_copy = ?
+                 WHERE hm.target_copy = ?
                        AND h.capture_time IS NULL
-               ORDER BY h.pickup_lib - (SELECT home_ou FROM actor.usr a WHERE a.id = h.usr), h.selection_depth DESC, h.request_time
-               LIMIT 1
+               ORDER BY
+                       actor.org_unit_proximity(h.pickup_lib, ?),
+                       h.selection_depth DESC,
+                       h.request_time
+               LIMIT $limit
        SQL
        return $id;
 }
 __PACKAGE__->register_method(
-       api_name        => 'open-ils.storage.action.hold_request.nearest_hold',
-       api_level       => 1,
-       method          => 'nearest_hold',
+       api_name        => 'open-ils.storage.action.hold_request.nearest_hold',
+       api_level       => 1,
+       stream          => 1,
+       method          => 'nearest_hold',
 );
 
 sub next_resp_group_id {
@@ -1069,7 +1073,7 @@ sub create_prox_list {
 
        my @prox_list;
        for my $cp (@$copies) {
-               my ($prox) = $self->method_lookup('open-ils.storage.asset.copy.proximity')->run( $cp->id, $lib );
+               my ($prox) = $self->method_lookup('open-ils.storage.asset.copy.proximity')->run( $cp, $lib );
                next unless (defined($prox));
                $prox_list[$prox] = [] unless defined($prox_list[$prox]);
                push @{$prox_list[$prox]}, $cp;