LP#1745499 De-Parallelify Item Status file upload
authorBill Erickson <berickxx@gmail.com>
Fri, 26 Jan 2018 21:42:08 +0000 (16:42 -0500)
committerJason Stephenson <jason@sigio.com>
Sun, 18 Feb 2018 15:55:02 +0000 (10:55 -0500)
Fetch copies in a series instead of in parallel when loading copy
barcodes from a file in the Item Status interface.  This helps avoid
excessive pcrud process count.

Since this causes the action to take a little longer, the commit also
includes a progress dialog indicating copy retrieve progress.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/web/js/ui/default/staff/cat/item/app.js

index e587818..be8e797 100644 (file)
@@ -234,8 +234,13 @@ function($scope , $location , $timeout , egCore , egGridDataProvider , itemSvc)
  * List view - grid stuff
  */
 .controller('ListCtrl', 
-       ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
-function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
+       ['$scope','$q','$routeParams','$location','$timeout','$window','egCore',
+        'egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
+        'egProgressDialog',
+function($scope , $q , $routeParams , $location , $timeout , $window , egCore , 
+         egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
+         egProgressDialog) {
+
     var copyId = [];
     var cp_list = $routeParams.idList;
     if (cp_list) {
@@ -282,18 +287,24 @@ function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
                 barcodes.push(line);
             });
 
-            if (barcodes.length > 0) {
-                var promises = [];
-                angular.forEach(barcodes, function (b) {
-                    promises.push(itemSvc.fetch(b));
-                });
+            // Serialize copy retrieval since there may be many, many copies.
+            function fetch_next_copy() {
+                var barcode = barcodes.pop();
+                egProgressDialog.increment();
 
-                $q.all(promises).then(
-                    function() {
-                        copyGrid.refresh();
-                        copyGrid.selectItems([itemSvc.copies[0].index]);
-                    }
-                );
+                if (!barcode) { // All done here.
+                    egProgressDialog.close();
+                    copyGrid.refresh();
+                    copyGrid.selectItems([itemSvc.copies[0].index]);
+                    return;
+                }
+
+                itemSvc.fetch(barcode).then(fetch_next_copy);
+            }
+
+            if (barcodes.length) {
+                egProgressDialog.open({value: 0, max: barcodes.length});
+                fetch_next_copy();
             }
         }
     });