From 6500c699758095da9dc25dee6c34986bcd4f6932 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 15 Dec 2020 07:40:45 -0800 Subject: [PATCH] LP1888723 Improve copy default status lookup Fixes an issue where a) default copy statuses were not getting correctly applied and b) the copy status org setting lookup was not correctly serialized, which can lead to actor drone exhaustion on the server (see also bug 1896285). Signed-off-by: Bill Erickson Signed-off-by: Ruth Frasur Signed-off-by: Galen Charlton --- .../staff/cat/volcopy/vol-edit.component.ts | 11 ++++++ .../staff/cat/volcopy/volcopy.component.ts | 2 +- .../app/staff/cat/volcopy/volcopy.service.ts | 39 +++++++++---------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts index 7dddc63546..12668bf4d1 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts @@ -142,6 +142,7 @@ export class VolEditComponent implements OnInit { } createCopies(volNode: HoldingsTreeNode, count: number) { + const copies = []; for (let i = 0; i < count; i++) { // Our context assumes copies are fleshed with volumes @@ -149,7 +150,10 @@ export class VolEditComponent implements OnInit { const copy = this.volcopy.createStubCopy(vol); copy.call_number(vol); this.context.findOrCreateCopyNode(copy); + copies.push(copy); } + + this.volcopy.setCopyStatus(copies); } createCopiesFromPopover(volNode: HoldingsTreeNode, popover: any) { @@ -166,6 +170,7 @@ export class VolEditComponent implements OnInit { createVols(orgNode: HoldingsTreeNode, count: number) { const vols = []; + const copies = []; for (let i = 0; i < count; i++) { // This will vivify the volNode if needed. @@ -177,9 +182,11 @@ export class VolEditComponent implements OnInit { // Our context assumes copies are fleshed with volumes const copy = this.volcopy.createStubCopy(vol); copy.call_number(vol); + copies.push(copy); this.context.findOrCreateCopyNode(copy); } + this.volcopy.setCopyStatus(copies); this.volcopy.setVolClassLabels(vols); } @@ -200,14 +207,18 @@ export class VolEditComponent implements OnInit { addStubCopies(volNode?: HoldingsTreeNode) { const nodes = volNode ? [volNode] : this.context.volNodes(); + const copies = []; nodes.forEach(vNode => { if (vNode.children.length === 0) { const vol = vNode.target; const copy = this.volcopy.createStubCopy(vol); copy.call_number(vol); + copies.push(copy); this.context.findOrCreateCopyNode(copy); } }); + + this.volcopy.setCopyStatus(copies); } applyVolValue(vol: IdlObject, key: string, value: any) { diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts index 9250cc24fb..0d8b797e40 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts @@ -281,7 +281,7 @@ export class VolCopyComponent implements OnInit { copies.push(copy); }); - return this.volcopy.setCopyStatus(copies, this.context.fastAdd); + return this.volcopy.setCopyStatus(copies); } fetchCopies(copyIds: number | number[]): Promise { diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts index 85b16e4be2..1396a8d346 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts @@ -349,40 +349,39 @@ export class VolCopyService { } // Sets the default copy status for a batch of copies. - setCopyStatus(copies: IdlObject[], fastAdd: boolean): Promise { + setCopyStatus(copies: IdlObject[]): Promise { + + const fastAdd = this.currentContext.fastAdd; const setting = fastAdd ? 'cat.default_copy_status_fast' : 'cat.default_copy_status_normal'; - let promise = Promise.resolve(); // Seralize - - copies.forEach(copy => { - - // Avoid unnecessary lookups. Copy may have been modified - // during a previous iteration of this loop. - if (!isNaN(copy.status())) { return; } + const orgs: any = {}; + copies.forEach(copy => orgs[copy.circ_lib()] = 1); - promise = promise.then(_ => - this.org.settings(setting, copy.circ_lib()) - - ).then(sets => { - - // 0 == Available; 5 == In Process - const stat = sets[setting] || (fastAdd ? 0 : 5); + let promise = Promise.resolve(); // Seralize - copies.forEach(copy2 => { - if (copy2.circ_lib() === copy.circ_lib()) { - copy2.status(stat); - } + // Pre-fetch needed org settings + Object.keys(orgs).forEach(org => { + promise = promise.then(_ => { + return this.org.settings(setting, +org) + .then(sets => { + orgs[org] = sets[setting] || (fastAdd ? 0 : 5); }); }); }); + promise.then(_ => { + Object.keys(orgs).forEach(org => { + copies.filter(copy => copy.circ_lib() === +org) + .forEach(copy => copy.status(orgs[org])); + }); + }); + return promise; } - saveDefaults(): Promise { // Scrub unnecessary content before storing. -- 2.43.2