LP#1350042 streaming patron search API
authorBill Erickson <berick@esilibrary.com>
Mon, 4 Aug 2014 17:10:49 +0000 (13:10 -0400)
committerBen Shum <bshum@biblio.org>
Fri, 29 Aug 2014 20:12:09 +0000 (16:12 -0400)
Adds an API name-based option to the standard patron search API to
respond with a stream of fleshed users, so the caller is not forced to
make additional fetch-by-ID calls to collect the user data.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm

index 4dd3c01..be97787 100644 (file)
@@ -1317,9 +1317,30 @@ __PACKAGE__->register_method(
     method   => "patron_adv_search",
     api_name => "open-ils.actor.patron.search.advanced"
 );
+
+__PACKAGE__->register_method(
+    method   => "patron_adv_search",
+    api_name => "open-ils.actor.patron.search.advanced.fleshed",
+    stream => 1,
+    # TODO: change when opensrf 'bundling' is merged.
+    # set a relatively small bundle size so the caller can start
+    # seeing results fairly quickly
+    max_chunk_size => 4096, # bundling
+
+    # api_level => 2, 
+    # pending opensrf work -- also, not sure if needed since we're not
+    # actaully creating an alternate vesrion, only offering to return a
+    # different format.
+    #
+    signature => {
+        desc => q/Returns a stream of fleshed user objects instead of
+            a pile of identifiers/
+    }
+);
+
 sub patron_adv_search {
-    my( $self, $client, $auth, $search_hash, 
-        $search_limit, $search_sort, $include_inactive, $search_ou ) = @_;
+    my( $self, $client, $auth, $search_hash, $search_limit, 
+        $search_sort, $include_inactive, $search_ou, $flesh_fields, $offset) = @_;
 
     my $e = new_editor(authtoken=>$auth);
     return $e->event unless $e->checkauth;
@@ -1341,9 +1362,17 @@ sub patron_adv_search {
             );
         }
     }
-    return $U->storagereq(
+
+    my $ids = $U->storagereq(
         "open-ils.storage.actor.user.crazy_search", $search_hash, 
-            $search_limit, $search_sort, $include_inactive, $e->requestor->ws_ou, $search_ou, $opt_boundary);
+        $search_limit, $search_sort, $include_inactive, 
+        $e->requestor->ws_ou, $search_ou, $opt_boundary, $offset);
+
+    return $ids unless $self->api_name =~ /fleshed/;
+
+    $client->respond(new_flesh_user($_, $flesh_fields, $e)) for @$ids;
+
+    return;
 }
 
 
index 06117ff..f55da8c 100644 (file)
@@ -642,6 +642,7 @@ sub patron_search {
     my $ws_ou = shift;
     my $search_org = shift || $ws_ou;
     my $opt_boundary = shift || 0;
+    my $offset = shift || 0;
 
     my $penalty_sort = 0;
 
@@ -796,6 +797,7 @@ sub patron_search {
           GROUP BY $group_list
           ORDER BY $order_by
           LIMIT $limit
+          OFFSET $offset
     SQL
 
     return actor::user->db_Main->selectcol_arrayref($select, {Columns=>[scalar(@$sort)]}, map {lc($_)} (@usrv,@phonev,@identv,@namev,@addrv));