From 84bed711249098679ae25f83eeb588871022ed19 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 24 Aug 2016 11:38:49 -0400 Subject: [PATCH] LP#1588948: Only attempt a bib update if the heading changes This should significantly reduce the churn on bibs and the time to save an authority where the heading that would propagate to bibs has not changed. Signed-off-by: Mike Rylander Signed-off-by: Bill Erickson --- Open-ILS/src/sql/Pg/999.functions.global.sql | 4 +- ...XXX.schema.authority-propage-edit-date.sql | 84 ++++++++++++++++++- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 04b0b29125..612a4ba3c2 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1658,10 +1658,10 @@ BEGIN RETURN NEW; END IF; - -- Unless there's a setting stopping us, propagate these updates to any linked bib records + -- Unless there's a setting stopping us, propagate these updates to any linked bib records when the heading changes PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_auto_update' AND enabled; - IF NOT FOUND THEN + IF NOT FOUND AND NEW.heading <> OLD.heading THEN PERFORM authority.propagate_changes(NEW.id); END IF; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql index b5bd37526c..3d53c033b9 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql @@ -1,8 +1,6 @@ BEGIN; -DROP FUNCTION authority.propagate_changes (BIGINT, BIGINT); - CREATE OR REPLACE FUNCTION authority.propagate_changes (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$ DECLARE @@ -58,5 +56,87 @@ INSERT INTO config.global_flag (name, enabled, label) VALUES ( ); +CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$ +DECLARE + ashs authority.simple_heading%ROWTYPE; + mbe_row metabib.browse_entry%ROWTYPE; + mbe_id BIGINT; + ash_id BIGINT; +BEGIN + + IF NEW.deleted IS TRUE THEN -- If this authority is deleted + DELETE FROM authority.bib_linking WHERE authority = NEW.id; -- Avoid updating fields in bibs that are no longer visible + DELETE FROM authority.full_rec WHERE record = NEW.id; -- Avoid validating fields against deleted authority records + DELETE FROM authority.simple_heading WHERE record = NEW.id; + -- Should remove matching $0 from controlled fields at the same time? + + -- XXX What do we about the actual linking subfields present in + -- authority records that target this one when this happens? + DELETE FROM authority.authority_linking + WHERE source = NEW.id OR target = NEW.id; + + RETURN NEW; -- and we're done + END IF; + + IF TG_OP = 'UPDATE' THEN -- re-ingest? + PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled; + + IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change + RETURN NEW; + END IF; + + -- Unless there's a setting stopping us, propagate these updates to any linked bib records when the heading changes + PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_auto_update' AND enabled; + + IF NOT FOUND AND NEW.heading <> OLD.heading THEN + PERFORM authority.propagate_changes(NEW.id); + END IF; + + DELETE FROM authority.simple_heading WHERE record = NEW.id; + DELETE FROM authority.authority_linking WHERE source = NEW.id; + END IF; + + INSERT INTO authority.authority_linking (source, target, field) + SELECT source, target, field FROM authority.calculate_authority_linking( + NEW.id, NEW.control_set, NEW.marc::XML + ); + + FOR ashs IN SELECT * FROM authority.simple_heading_set(NEW.marc) LOOP + + INSERT INTO authority.simple_heading (record,atag,value,sort_value,thesaurus) + VALUES (ashs.record, ashs.atag, ashs.value, ashs.sort_value, ashs.thesaurus); + ash_id := CURRVAL('authority.simple_heading_id_seq'::REGCLASS); + + SELECT INTO mbe_row * FROM metabib.browse_entry + WHERE value = ashs.value AND sort_value = ashs.sort_value; + + IF FOUND THEN + mbe_id := mbe_row.id; + ELSE + INSERT INTO metabib.browse_entry + ( value, sort_value ) VALUES + ( ashs.value, ashs.sort_value ); + + mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS); + END IF; + + INSERT INTO metabib.browse_entry_simple_heading_map (entry,simple_heading) VALUES (mbe_id,ash_id); + + END LOOP; + + -- Flatten and insert the afr data + PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_full_rec' AND enabled; + IF NOT FOUND THEN + PERFORM authority.reingest_authority_full_rec(NEW.id); + PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_rec_descriptor' AND enabled; + IF NOT FOUND THEN + PERFORM authority.reingest_authority_rec_descriptor(NEW.id); + END IF; + END IF; + + RETURN NEW; +END; +$func$ LANGUAGE PLPGSQL; + COMMIT; -- 2.43.2