the long-running users_of_interest method now streams responses to the client, upped...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 26 Jan 2007 20:25:04 +0000 (20:25 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 26 Jan 2007 20:25:04 +0000 (20:25 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6822 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Collections.pm

index 0b03285..bf77c7d 100644 (file)
@@ -92,9 +92,17 @@ __PACKAGE__->register_method(
 );
 
 
+__PACKAGE__->register_method(
+       method    => 'users_of_interest',
+       api_name  => 'open-ils.collections.users_of_interest.retrieve.atomic',
+   stream    => 1,
+);
+
 sub users_of_interest {
        my( $self, $conn, $auth, $age, $fine_level, $location ) = @_;
 
+   my $atomic = $self->api_name =~ /atomic/;
+
        return OpenILS::Event->new('BAD_PARAMS') 
                unless ($auth and $age and $fine_level and $location);
 
@@ -107,34 +115,44 @@ sub users_of_interest {
        # they need global perms to view users so no org is provided
        return $e->event unless $e->allowed('VIEW_USER'); 
 
-       my $data = $U->storagereq(
-               'open-ils.storage.money.collections.users_of_interest.atomic', 
-               $age, $fine_level, $location);
-
-       return [] unless $data and @$data;
-
-       for (@$data) {
-               my $u = $e->retrieve_actor_user(
-                       [
-                               $_->{usr},
-                               {
-                                       flesh                           => 1,
-                                       flesh_fields    => {au => ["groups","profile", "card"]},
-                                       select                  => {au => ["profile","id","dob", "card"]}
-                               }
-                       ]
-               ) or return $e->event;
-
-               $_->{usr} = {
-                       id                      => $u->id,
-                       dob             => $u->dob,
-                       profile => $u->profile->name,
-                       barcode => $u->card->barcode,
-                       groups  => [ map { $_->name } @{$u->groups} ],
-               };
-       }
-
-       return $data;
+   my $data = [];
+
+   my $ses = OpenSRF::AppSession->create('open-ils.storage');
+   my $req = $ses->request(
+      'open-ils.storage.money.collections.users_of_interest', 
+      $age, $fine_level, $location);
+
+   # let the client know we're still here
+   $conn->status( new OpenSRF::DomainObject::oilsContinueStatus );
+
+   while( my $resp = $req->recv(timeout => 600) ) {
+      return $req->failed if $req->failed;
+      my $hash = $resp->content;
+      next unless $hash;
+
+      my $u = $e->retrieve_actor_user(
+         [
+                $hash->{usr},
+                {
+                        flesh                          => 1,
+                        flesh_fields   => {au => ["groups","profile", "card"]},
+                        #select                        => {au => ["profile","id","dob", "card"]}
+                }
+         ]
+      ) or return $e->event;
+
+      $hash->{usr} = {
+         id                    => $u->id,
+         dob           => $u->dob,
+         profile       => $u->profile->name,
+         barcode       => $u->card->barcode,
+         groups        => [ map { $_->name } @{$u->groups} ],
+      };
+      
+      $conn->respond($hash);
+   }
+
+   return undef;
 }