Comment 3 for bug 1964986

Revision history for this message
Blake GH (bmagic) wrote : Re: Pull list can lose pagination when a patron has more than one penalty

This is a small tweak to the query to help get the "most likely" branches to have the issue:

select aou.shortname,count(*)
from
actor.org_unit aou
join action.hold_request ahr2 on (ahr2.pickup_lib=aou.id)
join
(
select ahr.id,count(*)
from
action.hold_request ahr
join actor.usr au on(au.id=ahr.usr)
join actor.usr_standing_penalty ausp on(ausp.usr=au.id 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%' AND (
  (csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR
  (csp.org_depth IS NOT NULL AND ahr.pickup_lib IN (
  SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth))
  )
 )
)
where
ahr.capture_time IS NULL AND
ahr.cancel_time IS NULL AND
csp.id IS NULL AND
(ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND
csp.id is null
group by 1
having count(*) > 1
) bug_ids
on (bug_ids.id=ahr2.id)
group by 1
order by 2 desc

Start testing from the first returned result.