LP#1727557 Webstaff load offline block list faster
authorBill Erickson <berickxx@gmail.com>
Mon, 21 May 2018 22:02:52 +0000 (18:02 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 4 Jun 2018 16:35:53 +0000 (12:35 -0400)
Insert the offline block patron data in a single insert to speed it up.
Also display a progress dialog while the data loads to better clarify
something is going on under the covers.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/staff/offline.js
Open-ILS/web/js/ui/default/staff/services/lovefield.js

index 947aa42..c75a140 100644 (file)
@@ -251,8 +251,12 @@ function($routeProvider , $locationProvider , $compileProvider) {
 ])
 
 .controller('OfflineCtrl', 
-           ['$q','$scope','$window','$location','$rootScope','egCore','egLovefield','$routeParams','$timeout','$http','ngToast','egConfirmDialog','egUnloadPrompt',
-    function($q , $scope , $window , $location , $rootScope , egCore , egLovefield , $routeParams , $timeout , $http , ngToast , egConfirmDialog , egUnloadPrompt) {
+           ['$q','$scope','$window','$location','$rootScope','egCore',
+            'egLovefield','$routeParams','$timeout','$http','ngToast',
+            'egConfirmDialog','egUnloadPrompt','egProgressDialog',
+    function($q , $scope , $window , $location , $rootScope , egCore ,
+             egLovefield , $routeParams , $timeout , $http , ngToast ,
+             egConfirmDialog , egUnloadPrompt , egProgressDialog) {
 
         // Immediately redirect if we're really offline
         if (!$window.navigator.onLine) {
@@ -388,6 +392,7 @@ function($routeProvider , $locationProvider , $compileProvider) {
         });
 
         $scope.downloadBlockList = function () {
+            egProgressDialog.open();
             var url = '/standalone/list.txt?ses='
                 + egCore.auth.token()
                 + '&' + new Date().getTime();
@@ -395,12 +400,9 @@ function($routeProvider , $locationProvider , $compileProvider) {
                 function (res) {
                     if (res.data) {
                         var lines = res.data.split('\n');
-                        egLovefield.destroyOfflineBlocks().then(function(){
-                            angular.forEach(lines, function (l) {
-                                var parts = l.split(' ');
-                                egLovefield.addOfflineBlock(parts[0], parts[1]);
-                            });
-                            return $q.when();
+                        return egLovefield.destroyOfflineBlocks()
+                        .then(function(){
+                            return egLovefield.addOfflineBlockBatch(lines);
                         }).then(function(){
                             ngToast.create(egCore.strings.OFFLINE_BLOCKLIST_SUCCESS);
                         });
@@ -409,7 +411,7 @@ function($routeProvider , $locationProvider , $compileProvider) {
                     ngToast.warning(egCore.strings.OFFLINE_BLOCKLIST_FAIL);
                     egCore.audio.play('warning.offline.blocklist_fail');
                 }
-            );
+            )['finally'](egProgressDialog.close);
         }
 
         $scope.createOfflineXactBlob = function () {
index d0cd9c1..e211744 100644 (file)
@@ -1,5 +1,9 @@
 var osb = lf.schema.create('offline', 2);
 
+// Leaving here as an example.  Note this had no impact
+// on load speed for large offline block lists.
+// osb.setPragma({enableBundledMode: true});
+
 osb.createTable('Object').
     addColumn('type', lf.Type.STRING).          // class hint
     addColumn('id', lf.Type.STRING).           // obj id
@@ -172,6 +176,35 @@ angular.module('egCoreMod')
         });
     }
 
+    service.addOfflineBlockBatch = function (lines) {
+        return connectOrGo().then(function() {
+
+            var rows = [];
+            var table = lf.offlineDB.getSchema().table('OfflineBlocks');
+            console.debug('compiling offline block rows');
+
+            lines.forEach(function(line) {
+                // slice/substring instead of split(' ') to handle barcodes
+                // with trailing spaces.
+                var barcode = line.slice(0, -2);
+                var reason = line.substring(line.length - 1);
+                rows.push(table.createRow({barcode: barcode, reason: reason}));
+            })
+
+            console.debug('inserting ' + rows.length + ' offline block rows');
+            return lf.offlineDB.
+                insertOrReplace().
+                into(table).
+                values(rows).
+                exec().
+                then(function() {
+                    console.debug(
+                        'inserted ' + rows.length + ' offline block rows');
+                });
+        });
+    }
+
+
     // Returns a promise with true for blocked, false for not blocked
     service.testOfflineBlock = function (barcode) {
         return connectOrGo().then(function() {