From 4cac0fdbf568a97a2b14ec9f9022e62afd8070e3 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 1 Nov 2021 12:36:31 -0400 Subject: [PATCH] LP#1949389: reduce number of PCRUD requests by subscription manager This patch changes how the AngularJS subscription manager fetches serial item templates. In particular, rather than issuing a PCRUD request for every org unit in the system, it fetches them in one fell swoop. This fixes an issue where loading the subscription manager in a large Evergreen consortium could lead to so many requests that it drives PCRUD into backlog mode, resulting in higher request latency across the board. To test ------- [1] Apply the patch. [2] Verify that the subscription manager lets you set the receiving template for each distribution and that the drop-down's contents changes if the distribution library is changed. [3] Verify that the Apply Binding Template action works and that the binding template drop-down(s) include the relevant copy templates. Note that if a binding template has been set already, the current binding template is _not_ displayed as the selected value in the drop-down. This is existing behavior that this patch does not aim to fix. Sponsored-by: BC Libraries Cooperative Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander Signed-off-by: Jeff Davis --- .../serials/directives/subscription_manager.js | 15 ++++----- .../js/ui/default/staff/serials/services/core.js | 38 +++++++++++++++++++--- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js b/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js index d06765762f..b96fadb07b 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js +++ b/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js @@ -59,10 +59,8 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , }; $scope.receiving_templates = {}; - angular.forEach(egCore.org.list(), function(org) { - egSerialsCoreSvc.fetch_templates(org.id()).then(function(list){ - $scope.receiving_templates[org.id()] = egCore.idl.toTypedHash(list); - }); + egSerialsCoreSvc.fetch_templates(egCore.org.list()).then(function(templates){ + $scope.receiving_templates = templates; }); $scope.add_subscription = function() { @@ -641,10 +639,11 @@ function($scope , $q , $uibModalInstance , egCore , egSerialsCoreSvc , $scope.rows = rows; $scope.args = { bind_unit_template : {} }; $scope.templates = {}; - angular.forEach(libs, function(org) { - egSerialsCoreSvc.fetch_templates(org.id).then(function(list){ - $scope.templates[org.id] = egCore.idl.toTypedHash(list); - }); + var _libs = libs.map(function(x) { + return x.id; + }); + egSerialsCoreSvc.fetch_templates(_libs).then(function(templates){ + $scope.templates = templates; }); }]) diff --git a/Open-ILS/web/js/ui/default/staff/serials/services/core.js b/Open-ILS/web/js/ui/default/staff/serials/services/core.js index 42e76dcc3f..bc0a1e2b5b 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/services/core.js +++ b/Open-ILS/web/js/ui/default/staff/serials/services/core.js @@ -703,11 +703,41 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm }); } - service.fetch_templates = function(org) { - return egCore.pcrud.search('act', - {owning_lib : egCore.org.fullPath(org, true)}, + // return a hash keyed by the supplied OU IDs of + // of the list of copy templates owned by the full OU path + // of each one + service.fetch_templates = function(orgs) { + var deferred = $q.defer(); + var _x = angular.isArray(orgs) ? orgs : [ orgs ]; + var _orgs = _x.map(function(o) { + return egCore.org.get(o); + }); + var _fps = {}; + var _relevant_orgs = []; + angular.forEach(_orgs, function(o) { + var _fp = egCore.org.fullPath(o, true); + _fps[o.id()] = _fp; + angular.forEach(_fp, function (o2) { + if (_relevant_orgs.indexOf(o2) === -1) { + _relevant_orgs.push(o2); + } + }); + }); + egCore.pcrud.search('act', + {owning_lib : _relevant_orgs}, {order_by : { act : 'name' }}, {atomic : true} - ); + ).then(function(list) { + var _tmpls = {}; + angular.forEach(_orgs, function(o) { + _tmpls[o.id()] = list.filter(function(x) { + return _fps[o.id()].indexOf(x.owning_lib()) > -1; + }).map(function(x) { + return egCore.idl.toTypedHash(x); + }); + }); + deferred.resolve(_tmpls); + }); + return deferred.promise; }; service.print_routing_lists = function (bibId, items, check, force, print_rl) { -- 2.11.0