[open-ils-commits] r13894 - in trunk/Open-ILS/src: perlmods/OpenILS/Application sql/Pg (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Aug 20 11:00:49 EDT 2009
Author: miker
Date: 2009-08-20 11:00:46 -0400 (Thu, 20 Aug 2009)
New Revision: 13894
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm
trunk/Open-ILS/src/sql/Pg/reporter-schema.sql
Log:
moving the simple-rec synchronization out of the DB for insert/update, and as a new trigger for "delete". This should finally address the ingest issues seen at some sites through the 1.4 series
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm 2009-08-20 08:08:11 UTC (rev 13893)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm 2009-08-20 15:00:46 UTC (rev 13894)
@@ -333,6 +333,8 @@
$cstore->request( 'open-ils.cstore.direct.metabib.metarecord_source_map.create' => $mrm )->gather(1);
$cstore->request( 'open-ils.cstore.direct.biblio.record_entry.update' => $bib )->gather(1);
+ $cstore->request( 'open-ils.cstore.json_query.atomic' => { from => [ 'reporter.simple_rec_update', $bib ] } )->gather(1);
+
$cstore->request( 'open-ils.cstore.transaction.commit' )->gather(1) || return undef;;
$cstore->disconnect;
Modified: trunk/Open-ILS/src/sql/Pg/reporter-schema.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/reporter-schema.sql 2009-08-20 08:08:11 UTC (rev 13893)
+++ trunk/Open-ILS/src/sql/Pg/reporter-schema.sql 2009-08-20 15:00:46 UTC (rev 13894)
@@ -174,34 +174,77 @@
CREATE VIEW reporter.super_simple_record AS SELECT * FROM reporter.materialized_simple_record;
+CREATE OR REPLACE FUNCTION reporter.simple_rec_update (r_id BIGINT, deleted BOOL) RETURNS BOOL AS $$
+DECLARE
+ new_data RECORD;
+BEGIN
+
+ DELETE FROM reporter.materialized_simple_record WHERE id = r_id;
+
+ IF NOT deleted THEN
+ INSERT INTO reporter.materialized_simple_record SELECT DISTINCT ON (id) * FROM reporter.old_super_simple_record WHERE id = NEW.record;
+ END IF;
+
+ RETURN TRUE;
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_update (r_id BIGINT) RETURNS BOOL AS $$
+ SELECT reporter.simple_rec_update($1, FALSE);
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_delete (r_id BIGINT) RETURNS BOOL AS $$
+ SELECT reporter.simple_rec_update($1, TRUE);
+$$ LANGUAGE SQL;
+
CREATE OR REPLACE FUNCTION reporter.simple_rec_sync () RETURNS TRIGGER AS $$
DECLARE
r_id BIGINT;
- new_data RECORD;
+ deleted BOOL;
BEGIN
IF TG_OP IN ('DELETE') THEN
r_id := OLD.record;
+ deleted := TRUE;
ELSE
r_id := NEW.record;
+ deleted := FALSE;
END IF;
- 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;
+ PERFORM reporter.simple_rec_update(r_id, deleted);
- IF TG_OP IN ('DELETE') THEN
+ IF deleted 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;
$$ LANGUAGE PLPGSQL;
-CREATE TRIGGER zzz_update_materialized_simple_record_tgr
- AFTER INSERT OR UPDATE OR DELETE ON metabib.real_full_rec
- FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_sync();
+--
+-- Disabling this by default for now, but we'll keep it around
+--
+--CREATE TRIGGER zzz_update_materialized_simple_record_tgr
+-- AFTER INSERT OR UPDATE OR DELETE ON metabib.real_full_rec
+-- FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_sync();
+CREATE OR REPLACE FUNCTION reporter.simple_rec_bib_sync () RETURNS TRIGGER AS $$
+BEGIN
+ IF NEW.deleted THEN
+ DELETE FROM reporter.materialized_simple_record WHERE id = NEW.id;
+ RETURN NEW;
+ ELSE
+ RETURN NEW;
+ END IF;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER zzz_update_materialized_simple_rec_delete_tgr
+ AFTER UPDATE ON biblio.record_entry
+ FOR EACH ROW EXECUTE PROCEDURE reporter.reporter.simple_rec_bib_sync();
+
+
CREATE OR REPLACE FUNCTION reporter.disable_materialized_simple_record_trigger () RETURNS VOID AS $$
DROP TRIGGER zzz_update_materialized_simple_record_tgr ON metabib.real_full_rec;
$$ LANGUAGE SQL;
More information about the open-ils-commits
mailing list