LP1761222 Holdings batch circ retrieval
authorBill Erickson <berickxx@gmail.com>
Tue, 5 Feb 2019 20:35:51 +0000 (15:35 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Fri, 21 Feb 2020 18:36:06 +0000 (13:36 -0500)
Fetch non-checked-in circulations for copies in the Holdings
maintenance grid (for due date display) in batch instead firing a
potentially vary large parallel batch of pcrud API calls.

This also limits due date display to items that have open circulations,
consistent with the XUL client.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Tiffany Little <tlittle@georgialibraries.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/web/js/ui/default/staff/cat/services/holdings.js

index 78055cf..73c91a3 100644 (file)
@@ -137,22 +137,29 @@ function(egCore , $q) {
                         cp.copy_alert_count = cp.copy_alerts.filter(function(aca) { return aca.ack_time == null ;}).length;
                     }
                     else cp.copy_alert_count = 0;
-
-                    var copy_circ = egCore.pcrud.search('combcirc', { target_copy : cp.id },
-                        {
-                            order_by : {combcirc : 'xact_start desc'},
-                            limit :  1
-                        }
-                    ).then(function(copy_circ) {
-                        if (copy_circ) {
-                            cp._circ = egCore.idl.toHash(copy_circ, true);
-                            cp._circ_lib = copy_circ.circ_lib();
-                            cp._duration = copy_circ.duration();
-                        }
-                        return copy_circ;
-                    });
                 });
 
+                // Grab the open circulation (i.e. checkin_time=null) for
+                // all of the copies we're rendering so we can display
+                // due date info.  There should only ever be one circulation
+                // at most with checkin_time=null for any copy.
+                var copyIds = svc.copies.map(function(cp) {return cp.id})
+                    .filter(function(id) {return Boolean(id)}); // avoid nulls
+
+                egCore.pcrud.search('circ', 
+                    {target_copy: copyIds, checkin_time: null}
+                ).then(
+                    null, // complete
+                    null, // error
+                    function(circ) {
+                        var cp = svc.copies.filter(function(c) { 
+                            return c.id == circ.target_copy() })[0];
+                        cp._circ = egCore.idl.toHash(circ, true);
+                        cp._circ_lib = circ.circ_lib();
+                        cp._duration = circ.duration();
+                    }
+                );
+
                 // create a label using just the unique part of the owner list
                 var index = 0;
                 var prev_owner_list;