From: Bill Erickson Date: Tue, 22 Oct 2019 15:31:14 +0000 (-0400) Subject: LP1849523 Ang cat holds batch retrieval X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=76bf7a9fa3d54acd6e9ceeb854d872a869a01ea7;p=working%2FEvergreen.git LP1849523 Ang cat holds batch retrieval Angular catalog leverages the new batch versions of the bib / metabib hold counts API to reduce the number of API calls needed per results page. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts index b2058e7aed..c77b5b3ee7 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts @@ -332,6 +332,17 @@ export class BibRecordService { return holdingsSummary; }); } + + // Batch hold counts lookup. + getHoldCounts(targetIds: number[], isMetarecord?: boolean): + Observable<{[id: string]: number}> { + + const method = isMetarecord ? + 'open-ils.circ.mmr.holds.count.batch' : + 'open-ils.circ.bre.holds.count.batch'; + + return this.net.request('open-ils.circ', method, targetIds); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts index b46e4ca0ba..0cca8880e3 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts @@ -43,7 +43,6 @@ export class ResultRecordComponent implements OnInit, OnDestroy { ngOnInit() { this.searchContext = this.staffCat.searchContext; - this.summary.getHoldCount(); this.isRecordSelected = this.basket.hasRecordId(this.summary.id); // Watch for basket changes caused by other components diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts index 869eff2e79..014505e13a 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts @@ -108,27 +108,30 @@ export class ResultsComponent implements OnInit, OnDestroy { // To reduce page display shuffling, avoid showing the list of // records until the first few are ready to render. shouldStartRendering(): boolean { - - if (this.searchHasResults()) { - const pageCount = this.searchContext.currentResultIds().length; - switch (pageCount) { - case 1: - return this.searchContext.result.records[0]; - default: - return this.searchContext.result.records[0] - && this.searchContext.result.records[1]; - } - } - - return false; + return ( + this.searchHasResults() && this.searchContext.result.records[0] + ); } fleshSearchResults(): void { const records = this.searchContext.result.records; if (!records || records.length === 0) { return; } - // Flesh the creator / editor fields with the user object. - this.bib.fleshBibUsers(records.map(r => r.record)); + setTimeout(() => { + // setTimeout here is not required, but it allows Angular to start + // rendering the results a bit sooner, before these actions complete. + + // Flesh the creator / editor fields with the user object. + this.bib.fleshBibUsers(records.map(r => r.record)); + + this.bib.getHoldCounts(this.searchContext.currentResultIds()) + .subscribe(result => { + const targetId = Object.keys(result)[0]; + const record = + records.filter(r => r.id === Number(targetId))[0]; + record.holdCount = result[targetId]; + }); + }); } searchIsDone(): boolean {