LP1849523 Ang cat holds batch retrieval
authorBill Erickson <berickxx@gmail.com>
Tue, 22 Oct 2019 15:31:14 +0000 (11:31 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 23 Oct 2019 18:21:48 +0000 (14:21 -0400)
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 <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts

index b2058e7..c77b5b3 100644 (file)
@@ -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);
+    }
 }
 
 
index b46e4ca..0cca888 100644 (file)
@@ -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
index 869eff2..014505e 100644 (file)
@@ -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 {