LP#1657237: Rewrite the hold target cache
authorMike Rylander <mrylander@gmail.com>
Wed, 18 Jan 2017 19:38:00 +0000 (14:38 -0500)
committerMike Rylander <mrylander@gmail.com>
Wed, 25 Jan 2017 16:27:21 +0000 (11:27 -0500)
We fixed the trigger that caused the problem in bug 167237, but now we need
to rewrite reporter.hold_request_record because T-holds are probably all
wrong.  No data was lost, we're just addressing the contents of a materialized
view.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Boyer <jboyer@library.in.gov>
Open-ILS/src/sql/Pg/upgrade/1004.function.hold-move-trigger-bug.sql

index 1e3dfd1..5a773af 100644 (file)
@@ -47,5 +47,31 @@ BEGIN
 END;
 $$ LANGUAGE PLPGSQL;
 
+TRUNCATE TABLE reporter.hold_request_record;
+INSERT INTO reporter.hold_request_record 
+SELECT  id,
+        target,
+        hold_type,
+        CASE
+                WHEN hold_type = 'T'
+                        THEN target
+                WHEN hold_type = 'I'
+                        THEN (SELECT ssub.record_entry FROM serial.subscription ssub JOIN serial.issuance si ON (si.subscription = ssub.id) WHERE si.id = ahr.target)
+                WHEN hold_type = 'V'
+                        THEN (SELECT cn.record FROM asset.call_number cn WHERE cn.id = ahr.target)
+                WHEN hold_type IN ('C','R','F')
+                        THEN (SELECT cn.record FROM asset.call_number cn JOIN asset.copy cp ON (cn.id = cp.call_number) WHERE cp.id = ahr.target)
+                WHEN hold_type = 'M'
+                        THEN (SELECT mr.master_record FROM metabib.metarecord mr WHERE mr.id = ahr.target)
+                WHEN hold_type = 'P'
+                        THEN (SELECT bmp.record FROM biblio.monograph_part bmp WHERE bmp.id = ahr.target)
+        END AS bib_record
+  FROM  action.hold_request ahr;
+REINDEX TABLE reporter.hold_request_record;
+
 COMMIT;
 
+ANALYZE reporter.hold_request_record;
+