LP1896285 Patron search add to bucket serialize
authorBill Erickson <berickxx@gmail.com>
Wed, 2 Dec 2020 21:52:47 +0000 (13:52 -0800)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Jan 2021 20:43:41 +0000 (15:43 -0500)
Add a batch of patrons to a bucket one patron at a time to avoid
overwhelming the server with bucket item create requests and potentially
exhausing the open-ils.actor service.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/web/js/ui/default/staff/circ/patron/app.js

index 0b1a1a7..f602398 100644 (file)
@@ -633,24 +633,26 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore ,
         if (recs.length == 0) return;
         var added_count = 0;
         var failed_count = 0;
-        var p = [];
+        var promise = $q.when();
         angular.forEach(recs,
             function(rec) {
                 var item = new egCore.idl.cubi();
                 item.bucket(data.id());
                 item.target_user(rec.id());
-                p.push(egCore.net.request(
-                    'open-ils.actor',
-                    'open-ils.actor.container.item.create',
-                    egCore.auth.token(), 'user', item
-                ).then(
+                promise = promise.then(function() {
+                    return egCore.net.request(
+                        'open-ils.actor',
+                        'open-ils.actor.container.item.create',
+                        egCore.auth.token(), 'user', item
+                    );
+                }).then(
                     function(){ added_count++ },
                     function(){ failed_count++ }
-                ));
+                );
             }
         );
 
-        $q.all(p).then( function () {
+        promise.then( function () {
             if (added_count) ngToast.create($interpolate(egCore.strings.BUCKET_ADD_SUCCESS)({ count: ''+added_count, name: data.name()} ));
             if (failed_count) ngToast.warning($interpolate(egCore.strings.BUCKET_ADD_FAIL)({ count: ''+failed_count, name: data.name() } ));
         });