optimized on-shelf holds retrieval. only grab the IDs up front and flesh transit...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 20 Nov 2008 21:14:53 +0000 (21:14 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 20 Nov 2008 21:14:53 +0000 (21:14 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2_4@11288 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm

index e1fe4eb..42a6412 100644 (file)
@@ -912,11 +912,10 @@ sub flesh_hold_notices {
 }
 
 
-
-
 __PACKAGE__->register_method(
        method => 'fetch_captured_holds',
        api_name        => 'open-ils.circ.captured_holds.on_shelf.retrieve',
+    stream => 1,
        signature       => q/
                Returns a list of un-fulfilled holds for a given title id
                @param authtoken The login session key
@@ -927,6 +926,7 @@ __PACKAGE__->register_method(
 __PACKAGE__->register_method(
        method => 'fetch_captured_holds',
        api_name        => 'open-ils.circ.captured_holds.id_list.on_shelf.retrieve',
+    stream => 1,
        signature       => q/
                Returns a list ids of un-fulfilled holds for a given title id
                @param authtoken The login session key
@@ -943,36 +943,50 @@ sub fetch_captured_holds {
 
        $org ||= $e->requestor->ws_ou;
 
-       my $holds = $e->search_action_hold_request(
-               { 
-                       capture_time            => { "!=" => undef },
-                       current_copy            => { "!=" => undef },
-                       fulfillment_time        => undef,
-                       pickup_lib                      => $org,
-                       cancel_time                     => undef,
-               }
-       );
-
-       my @res;
-       for my $h (@$holds) {
-               my $copy = $e->retrieve_asset_copy($h->current_copy)
-                       or return $e->event;
-               push( @res, $h ) if 
-                       $copy->status == OILS_COPY_STATUS_ON_HOLDS_SHELF;
-       }
+    my $hold_ids = $e->json_query(
+        { 
+            select => { ahr => ['id'] },
+            from => {
+                ahr => {
+                    acp => {
+                        field => 'id',
+                        fkey => 'current_copy'
+                    },
+                }
+            }, 
+            where => {
+                '+acp' => { status => OILS_COPY_STATUS_ON_HOLDS_SHELF },
+                '+ahr' => {
+                    capture_time               => { "!=" => undef },
+                    current_copy               => { "!=" => undef },
+                    fulfillment_time   => undef,
+                    pickup_lib                 => $org,
+                    cancel_time                        => undef,
+                }
+            }
+        },
+    );
 
-       if( ! $self->api_name =~ /id_list/ ) {
-               flesh_hold_transits(\@res);
-               flesh_hold_notices(\@res, $e);
-       }
+    for my $hold_id (@$hold_ids) {
+        if($self->api_name =~ /id_list/) {
+            $conn->respond($hold_id->{id});
+            next;
+        } else {
+            $conn->respond(
+                $e->retrieve_action_hold_request([
+                    $hold_id->{id},
+                    {
+                        flesh => 1,
+                        flesh_fields => {ahr => ['notifications', 'transit']},
+                        order_by => {anh => 'notify_time desc'}
+                    }
+                ])
+            );
+        }
+    }
 
-       if( $self->api_name =~ /id_list/ ) {
-               return [ map { $_->id } @res ];
-       } else {
-               return \@res;
-       }
+    return undef;
 }
-
 __PACKAGE__->register_method(
        method  => "check_title_hold",
        api_name        => "open-ils.circ.title_hold.is_possible",