configurable chunking of the holds stream to avoid the xulrunner "I forgot the chunke...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 2 Oct 2010 15:47:28 +0000 (15:47 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 2 Oct 2010 15:47:28 +0000 (15:47 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18136 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
Open-ILS/web/opac/extras/circ/alt_pull_list.html

index 143caeb..7b37e28 100644 (file)
@@ -1341,6 +1341,9 @@ sub print_hold_pull_list_stream {
     delete($$params{org_id}) unless (int($$params{org_id}));
     delete($$params{limit}) unless (int($$params{limit}));
     delete($$params{offset}) unless (int($$params{offset}));
+    delete($$params{chunk_size}) unless (int($$params{chunk_size}));
+    delete($$params{chunk_size}) if  ($$params{chunk_size} && $$params{chunk_size} > 50); # keep the size reasonable
+    $$params{chunk_size} ||= 10;
 
     $$params{org_id} = (defined $$params{org_id}) ? $$params{org_id}: $e->requestor->ws_ou;
     return $e->die_event unless $e->allowed('VIEW_HOLD', $$params{org_id });
@@ -1409,21 +1412,28 @@ sub print_hold_pull_list_stream {
 
     $logger->info("about to stream back " . scalar(@$holds_ids) . " holds");
 
-    $client->respond(
-        $e->retrieve_action_hold_request([
+    my @chunk;
+    for my $hid (@$holds_ids) {
+        push @chunk, $e->retrieve_action_hold_request([
             $_->{"id"}, {
                 "flesh" => 3,
                 "flesh_fields" => {
                     "ahr" => ["usr", "current_copy"],
+                    "au"  => ["card"],
                     "acp" => ["location", "call_number"],
                     "acn" => ["record"]
                 }
             }
-        ])
-    ) foreach @$holds_ids;
+        ]);
 
+        if (@chunk >= $$params{chunk_size}) {
+            $client->respond( \@chunk );
+            @chunk = ();
+        }
+    }
+    $client->respond_complete( \@chunk ) if (@chunk);
     $e->disconnect;
-    undef;
+    return undef;
 }
 
 
index 6302ac2..c85fcf8 100644 (file)
                     { async : true,
                       params: [
                         user.authtoken,
-                        { org_id   : cgi.param('o'),
-                          limit    : cgi.param('limit'),
-                          offset   : cgi.param('offset'),
-                          sort     : sort_order
+                        { org_id     : cgi.param('o'),
+                          limit      : cgi.param('limit'),
+                          offset     : cgi.param('offset'),
+                          chunk_size : cgi.param('chunk_size'),
+                          sort       : sort_order
                         }
                       ],
                       onresponse : function (r) {
-                        var hold_fm = openils.Util.readResponse(r);
-
-                        // hashify the hold
-                        var hold = hold_fm.toHash(true);
-                        hold.current_copy = hold_fm.current_copy().toHash(true);
-                        hold.current_copy.location = hold_fm.current_copy().location().toHash(true);
-                        hold.current_copy.call_number = hold_fm.current_copy().call_number().toHash(true);
-                        hold.current_copy.call_number.record = hold_fm.current_copy().call_number().record().toHash(true);
-
-                        // clone the template's html
-                        var tr = dojo.clone(
-                            dojo.query("tr", dojo.byId('template'))[0]
-                        );
-                        dojo.query("td:not([type])", tr).forEach(
-                            function(td) {
-                                td.innerHTML =
-                                    dojo.string.substitute(td.innerHTML, hold);
-                            }
-                        );
-
-                        new openils.BibTemplate({
-                            root : tr,
-                            xml  : dojox.xml.parser.parse(hold.current_copy.call_number.record.marc),
-                            delay: false
+                        dojo.forEach( openils.Util.readResponse(r), function (hold_fm) {
+    
+                            // hashify the hold
+                            var hold = hold_fm.toHash(true);
+                            hold.usr = hold_fm.usr().toHash(true);
+                            hold.usr.card = hold_fm.usr().card().toHash(true);
+                            hold.current_copy = hold_fm.current_copy().toHash(true);
+                            hold.current_copy.location = hold_fm.current_copy().location().toHash(true);
+                            hold.current_copy.call_number = hold_fm.current_copy().call_number().toHash(true);
+                            hold.current_copy.call_number.record = hold_fm.current_copy().call_number().record().toHash(true);
+    
+                            // clone the template's html
+                            var tr = dojo.clone(
+                                dojo.query("tr", dojo.byId('template'))[0]
+                            );
+                            dojo.query("td:not([type])", tr).forEach(
+                                function(td) {
+                                    td.innerHTML =
+                                        dojo.string.substitute(td.innerHTML, hold);
+                                }
+                            );
+    
+                            new openils.BibTemplate({
+                                root : tr,
+                                xml  : dojox.xml.parser.parse(hold.current_copy.call_number.record.marc),
+                                delay: false
+                            });
+    
+                            dojo.place(tr, "target");
                         });
-
-                        dojo.place(tr, "target");
-
-
                       },
                     oncomplete : function () {
                      progress_dialog.hide(); window.print() }