From 4ec26f05c29ed3160529c77c2728ab7a1146c224 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 21 May 2018 18:02:52 -0400 Subject: [PATCH] LP#1727557 Webstaff load offline block list faster 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 --- Open-ILS/web/js/ui/default/staff/offline.js | 20 +++++++------ .../web/js/ui/default/staff/services/lovefield.js | 33 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/offline.js b/Open-ILS/web/js/ui/default/staff/offline.js index 947aa42858..c75a14066d 100644 --- a/Open-ILS/web/js/ui/default/staff/offline.js +++ b/Open-ILS/web/js/ui/default/staff/offline.js @@ -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 () { diff --git a/Open-ILS/web/js/ui/default/staff/services/lovefield.js b/Open-ILS/web/js/ui/default/staff/services/lovefield.js index d0cd9c12ee..e211744b0b 100644 --- a/Open-ILS/web/js/ui/default/staff/services/lovefield.js +++ b/Open-ILS/web/js/ui/default/staff/services/lovefield.js @@ -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() { -- 2.11.0