JBAS-1405 Revert custom hold queue stats code
authorBill Erickson <berickxx@gmail.com>
Mon, 6 Feb 2017 22:11:53 +0000 (17:11 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Return to using the custom hold queue position calculation code.
This merely moves the logic from the DB back into the Perl code.  The
query logic is unchanged.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/sql/schema/deploy/revert-custom-qstats.sql [new file with mode: 0644]
KCLS/sql/schema/revert/revert-custom-qstats.sql [new file with mode: 0644]
KCLS/sql/schema/sqitch.plan
KCLS/sql/schema/verify/revert-custom-qstats.sql [new file with mode: 0644]
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

diff --git a/KCLS/sql/schema/deploy/revert-custom-qstats.sql b/KCLS/sql/schema/deploy/revert-custom-qstats.sql
new file mode 100644 (file)
index 0000000..275298b
--- /dev/null
@@ -0,0 +1,8 @@
+-- Deploy kcls-evergreen:revert-custom-qstats to pg
+-- requires: backstage-exports-continued
+
+BEGIN;
+
+DROP FUNCTION IF EXISTS action.get_hold_queue_status_by_id(INTEGER);
+
+COMMIT;
diff --git a/KCLS/sql/schema/revert/revert-custom-qstats.sql b/KCLS/sql/schema/revert/revert-custom-qstats.sql
new file mode 100644 (file)
index 0000000..a73ad48
--- /dev/null
@@ -0,0 +1,19 @@
+-- Revert kcls-evergreen:revert-custom-qstats from pg
+
+BEGIN;
+
+CREATE OR REPLACE FUNCTION get_hold_queue_status_by_id(integer) 
+    RETURNS TABLE(id integer, cut_in_line boolean, request_time timestamp with time zone)
+    LANGUAGE sql STABLE
+    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; 
+$_$;
+
+COMMIT;
+
index 34cfffc..3e3b152 100644 (file)
@@ -42,3 +42,4 @@ purge-holds [audit-table-maint] 2016-09-21T16:01:57Z Bill Erickson <berickxx@gma
 2.7-to-2.9-upgrade [backstage-exports-continued] 2016-12-09T20:27:17Z Bill Erickson <berickxx@gmail.com> # 2.7 to 2.9 Upgrade
 2.7-to-2.9-upgrade-part-2 [2.7-to-2.9-upgrade] 2016-12-12T15:19:07Z Bill Erickson <berickxx@gmail.com> # 2.7 to 2.9 Upgrade Secondary Updates
 pg-9.6-prep [2.7-to-2.9-upgrade-part-2] 2017-03-20T15:59:10Z Bill Erickson,,, <berick@cylinders> # Prep for PG 9.6
+revert-custom-qstats [backstage-exports-continued] 2017-02-06T22:09:42Z Bill Erickson <berickxx@gmail.com> # Remove custom hold queue position func
diff --git a/KCLS/sql/schema/verify/revert-custom-qstats.sql b/KCLS/sql/schema/verify/revert-custom-qstats.sql
new file mode 100644 (file)
index 0000000..78d1abd
--- /dev/null
@@ -0,0 +1,7 @@
+-- Verify kcls-evergreen:revert-custom-qstats on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;
index 8d18aa9..82c0b2a 100644 (file)
@@ -1387,7 +1387,35 @@ 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
-        from => [ "action.get_hold_queue_status_by_id", $hold->id ]
+        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
     });
 
     if (!@$q_holds) { # none? maybe we don't have a map ...