Advertisement
Guest User

Fleshing holds in the web client, alt route to ausp

a guest
Jun 5th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. explain analyze SELECT "ahopl".capture_time, "ahopl".current_copy, "ahopl".email_notify, "ahopl".expire_time, "ahopl".fulfillment_lib, "ahopl".fulfillment_staff, "ahopl".fulfillment_time, "ahopl".hold_type, "ahopl".holdable_formats, "ahopl".id, "ahopl".phone_notify, "ahopl".sms_notify, "ahopl".sms_carrier, "ahopl".pickup_lib, "ahopl".prev_check_time, "ahopl".request_lib, "ahopl".request_time, "ahopl".requestor, "ahopl".selection_depth, "ahopl".selection_ou, "ahopl".target, "ahopl".usr, "ahopl".cancel_time, "ahopl".frozen, "ahopl".thaw_date, "ahopl".shelf_time, "ahopl".cancel_cause, "ahopl".cancel_note, "ahopl".cut_in_line, "ahopl".mint_condition, "ahopl".shelf_expire_time, "ahopl".current_shelf_lib, "ahopl".copy_location_order_position, "ahopl".usr_first_given_name, "ahopl".usr_second_given_name, "ahopl".usr_family_name, "ahopl".usr_prefix, "ahopl".usr_suffix, "ahopl".usr_alias_or_first_given_name, "ahopl".usr_display_name, "ahopl".usr_alias_or_display_name, "ahopl".usr_alias, "ahopl".call_number_label, "ahopl".issuance_label, "ahopl".is_staff_hold, "ahopl".potential_copies, "ahopl".behind_desk FROM (
  2. SELECT
  3. ahr.*,
  4. COALESCE(acplo.position, acpl_ordered.fallback_position) AS
  5. copy_location_order_position,
  6. CASE WHEN au.alias IS NOT NULL THEN
  7. au.alias
  8. ELSE
  9. au.first_given_name
  10. END AS usr_alias_or_first_given_name,
  11. au.first_given_name AS usr_first_given_name,
  12. au.second_given_name AS usr_second_given_name,
  13. au.family_name AS usr_family_name,
  14. au.prefix AS usr_prefix,
  15. au.suffix AS usr_suffix,
  16. au.alias AS usr_alias,
  17. CASE WHEN au.alias IS NOT NULL THEN
  18. au.alias
  19. ELSE
  20. REGEXP_REPLACE(ARRAY_TO_STRING(ARRAY[
  21. COALESCE(au.family_name, ''),
  22. COALESCE(au.suffix, ''),
  23. ', ',
  24. COALESCE(au.prefix, ''),
  25. COALESCE(au.first_given_name, ''),
  26. COALESCE(au.second_given_name, '')
  27. ], ' '), E'\\s+,', ',')
  28. END AS usr_alias_or_display_name,
  29. REGEXP_REPLACE(ARRAY_TO_STRING(ARRAY[
  30. COALESCE(au.family_name, ''),
  31. COALESCE(au.suffix, ''),
  32. ', ',
  33. COALESCE(au.prefix, ''),
  34. COALESCE(au.first_given_name, ''),
  35. COALESCE(au.second_given_name, '')
  36. ], ' '), E'\\s+,', ',') AS usr_display_name,
  37. TRIM(acnp.label || ' ' || acn.label || ' ' || acns.label)
  38. AS call_number_label,
  39. siss.label AS issuance_label,
  40. (ahr.usr <> ahr.requestor) AS is_staff_hold,
  41. ahcm_1.copy_count AS potential_copies
  42. FROM action.hold_request ahr
  43. JOIN asset.copy acp ON (acp.id = ahr.current_copy)
  44. JOIN asset.call_number acn ON (acp.call_number = acn.id)
  45. JOIN asset.call_number_prefix acnp ON (acn.prefix = acnp.id)
  46. JOIN asset.call_number_suffix acns ON (acn.suffix = acns.id)
  47. JOIN actor.usr au ON (au.id = ahr.usr)
  48. JOIN (
  49. SELECT *, (ROW_NUMBER() OVER (ORDER BY name) + 1000000) AS fallback_position
  50. FROM asset.copy_location
  51. ) acpl_ordered ON (acpl_ordered.id = acp.location)
  52. LEFT JOIN actor.usr_standing_penalty ausp
  53. ON (au.id = ausp.usr AND (ausp.stop_date IS NULL OR ausp.stop_date > NOW()))
  54. LEFT JOIN config.standing_penalty csp
  55. ON (
  56. csp.id = ausp.standing_penalty AND
  57. csp.block_list LIKE '%CAPTURE%' AND (
  58. (csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR
  59. (csp.org_depth IS NOT NULL AND ahr.pickup_lib IN (
  60. SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth))
  61. )
  62. )
  63. )
  64. JOIN (
  65. SELECT COUNT(target_copy) AS copy_count, hold
  66. FROM action.hold_copy_map
  67. GROUP BY 2
  68. ) ahcm_1 ON (ahcm_1.hold = ahr.id)
  69. LEFT JOIN serial.issuance siss
  70. ON (ahr.hold_type = 'I' AND siss.id = ahr.target)
  71. LEFT JOIN asset.copy_location_order acplo
  72. ON (acp.location = acplo.location AND
  73. acp.circ_lib = acplo.org)
  74. WHERE
  75. ahr.capture_time IS NULL AND
  76. ahr.cancel_time IS NULL AND
  77. csp.id IS NULL AND
  78. (ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND
  79. acp.status IN (0,7)
  80. ) AS "ahopl" WHERE "ahopl".id = '4489817';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement