[open-ils-commits] r9475 - branches/rel_1_2/Open-ILS/src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Apr 28 08:55:06 EDT 2008
Author: miker
Date: 2008-04-28 08:15:05 -0400 (Mon, 28 Apr 2008)
New Revision: 9475
Modified:
branches/rel_1_2/Open-ILS/src/sql/Pg/reporter-schema.sql
branches/rel_1_2/Open-ILS/src/sql/Pg/upgrade_simple_record.sql
Log:
improved concurrency detection
Modified: branches/rel_1_2/Open-ILS/src/sql/Pg/reporter-schema.sql
===================================================================
--- branches/rel_1_2/Open-ILS/src/sql/Pg/reporter-schema.sql 2008-04-28 07:42:25 UTC (rev 9474)
+++ branches/rel_1_2/Open-ILS/src/sql/Pg/reporter-schema.sql 2008-04-28 12:15:05 UTC (rev 9475)
@@ -158,13 +158,24 @@
CREATE VIEW reporter.super_simple_record AS SELECT * FROM reporter.materialized_simple_record;
CREATE OR REPLACE FUNCTION reporter.simple_rec_sync () RETURNS TRIGGER AS $$
+DECLARE
+ r_id BIGINT;
+ new_data RECORD;
BEGIN
- IF TG_OP IN ('UPDATE','DELETE') THEN
- DELETE FROM reporter.materialized_simple_record WHERE id = OLD.record;
+ IF TG_OP IN ('DELETE') THEN
+ r_id := OLD.record;
+ ELSE
+ r_id := NEW.record;
END IF;
- IF TG_OP IN ('INSERT','UPDATE') AND NOT NEW.deleted THEN
- INSERT INTO reporter.materialized_simple_record SELECT * FROM reporter.old_super_simple_record WHERE id = NEW.record;
+ SELECT * INTO new_data FROM reporter.materialized_simple_record WHERE id = r_id FOR UPDATE;
+ DELETE FROM reporter.materialized_simple_record WHERE id = r_id;
+
+ IF TG_OP IN ('DELETE') THEN
+ RETURN OLD;
+ ELSE
+ INSERT INTO reporter.materialized_simple_record SELECT DISTINCT ON (id) * FROM reporter.old_super_simple_record WHERE id = NEW.record;
+ RETURN NEW;
END IF;
END;
Modified: branches/rel_1_2/Open-ILS/src/sql/Pg/upgrade_simple_record.sql
===================================================================
--- branches/rel_1_2/Open-ILS/src/sql/Pg/upgrade_simple_record.sql 2008-04-28 07:42:25 UTC (rev 9474)
+++ branches/rel_1_2/Open-ILS/src/sql/Pg/upgrade_simple_record.sql 2008-04-28 12:15:05 UTC (rev 9475)
@@ -33,13 +33,24 @@
GROUP BY 1,2,3,4,5,6,8,9;
CREATE OR REPLACE FUNCTION reporter.simple_rec_sync () RETURNS TRIGGER AS $$
+DECLARE
+ r_id BIGINT;
+ new_data RECORD;
BEGIN
- IF TG_OP IN ('UPDATE','DELETE') THEN
- DELETE FROM reporter.materialized_simple_record WHERE id = OLD.record;
+ IF TG_OP IN ('DELETE') THEN
+ r_id := OLD.record;
+ ELSE
+ r_id := NEW.record;
END IF;
- IF TG_OP IN ('INSERT','UPDATE') AND NOT NEW.deleted THEN
- INSERT INTO reporter.materialized_simple_record SELECT * FROM reporter.old_super_simple_record WHERE id = NEW.record;
+ SELECT * INTO new_data FROM reporter.materialized_simple_record WHERE id = r_id FOR UPDATE;
+ DELETE FROM reporter.materialized_simple_record WHERE id = r_id;
+
+ IF TG_OP IN ('DELETE') THEN
+ RETURN OLD;
+ ELSE
+ INSERT INTO reporter.materialized_simple_record SELECT DISTINCT ON (id) * FROM reporter.old_super_simple_record WHERE id = NEW.record;
+ RETURN NEW;
END IF;
END;
More information about the open-ils-commits
mailing list