From b2b9ec27a4c99b87b29a9d23fd323193bf26397e Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 1 Feb 2023 18:06:12 -0500 Subject: [PATCH] LP#2004520: WIP - dedupe search for nearest holds 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 --- .../lib/OpenILS/Application/Storage/Publisher/action.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm index c519e63ee0..8771cd8a8a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm @@ -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 -- 2.11.0