LP#2004520: WIP - dedupe search for nearest holds user/gmcharlt/lp2004520_dedupe_nearest_hold-wip
authorGalen Charlton <gmc@equinoxOLI.org>
Wed, 1 Feb 2023 23:06:12 +0000 (18:06 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 1 Feb 2023 23:06:12 +0000 (18:06 -0500)
This patch removes a source of duplicate hold IDs returned
by open-ils.storage.action.hold_request.nearest_hold by fixing
the part of the query that looks for standing penalties that block
capture.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm

index c519e63..8771cd8 100644 (file)
@@ -573,10 +573,14 @@ sub nearest_hold {
             JOIN permission.grp_tree pgt ON (au.profile = pgt.id)
             JOIN asset.copy acp ON (hm.target_copy = acp.id)
             LEFT JOIN config.rule_age_hold_protect cahp ON (acp.age_protect = cahp.id)
-            LEFT JOIN actor.usr_standing_penalty ausp
-                ON ( au.id = ausp.usr AND ( ausp.stop_date IS NULL OR ausp.stop_date > NOW() ) )
-            LEFT JOIN config.standing_penalty csp
-                ON ( csp.id = ausp.standing_penalty AND csp.block_list LIKE '%CAPTURE%' )
+            LEFT JOIN (
+                SELECT ausp.usr, ausp.id
+                FROM actor.usr_standing_penalty ausp
+                JOIN config.standing_penalty csp
+                        ON ( csp.id = ausp.standing_penalty AND csp.block_list LIKE '%CAPTURE%' )
+                WHERE ausp.stop_date IS NULL OR ausp.stop_date > NOW()
+                LIMIT 1
+            ) blocking_penalties ON blocking_penalties.usr = au.id
             LEFT JOIN LATERAL (
                 SELECT OILS_JSON_TO_TEXT(value) AS age
                   FROM actor.org_unit_ancestor_setting('circ.pickup_hold_stalling.soft', h.pickup_lib)
@@ -609,7 +613,7 @@ sub nearest_hold {
             AND h.cancel_time IS NULL
             AND (h.expire_time IS NULL OR h.expire_time > NOW())
             AND h.frozen IS FALSE
-            AND csp.id IS NULL
+            AND blocking_penalties.id IS NULL
         ORDER BY CASE WHEN h.hold_type IN ('R','F') THEN 0 ELSE 1 END, $holdsort
         LIMIT $limit
     SQL