KMIG-187: Hold Queue Position
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:05:30 +0000 (17:05 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: bba2c05

KCLS/sql/kmig-187.sql [new file with mode: 0644]
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

diff --git a/KCLS/sql/kmig-187.sql b/KCLS/sql/kmig-187.sql
new file mode 100644 (file)
index 0000000..0abc9c6
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE OR REPLACE FUNCTION action.get_hold_queue_status_by_id(INTEGER)
+RETURNS TABLE(id INTEGER, cut_in_line BOOLEAN, request_time timestamp with time zone) 
+AS $$
+WITH holds(holdid) AS 
+( SELECT acm.hold FROM action.hold_copy_map acm 
+  JOIN action.hold_copy_map acm2 USING(target_copy) 
+  WHERE acm2.hold=$1) 
+  SELECT id, cut_in_line, request_time FROM action.hold_request 
+  WHERE id IN (SELECT holdid FROM holds) 
+  ORDER BY coalesce(cut_in_line, false ) DESC, request_time; 
+$$ 
+LANGUAGE SQL STABLE;
index c7a9b9c..a120204 100644 (file)
@@ -1368,35 +1368,7 @@ sub retrieve_hold_queue_status_impl {
 
         # fetch cut_in_line and request_time since they're in the order_by
         # and we're asking for distinct values
-        select => {ahr => ['id', 'cut_in_line', 'request_time']},
-        from   => 'ahr',
-        where => {
-            id => { in => {
-                select => { ahcm => ['hold'] },
-                from   => {
-                    'ahcm' => {
-                        'ahcm2' => {
-                            'class' => 'ahcm',
-                            'field' => 'target_copy',
-                            'fkey'  => 'target_copy'
-                        }
-                    }
-                },
-                where => { '+ahcm2' => { hold => $hold->id } },
-                distinct => 1
-            }}
-        },
-        order_by => [
-            {
-                "class" => "ahr",
-                "field" => "cut_in_line",
-                "transform" => "coalesce",
-                "params" => [ 0 ],
-                "direction" => "desc"
-            },
-            { "class" => "ahr", "field" => "request_time" }
-        ],
-        distinct => 1
+        from => [ "action.get_hold_queue_status_by_id", $hold->id ]
     });
 
     if (!@$q_holds) { # none? maybe we don't have a map ...