From 471998aed3b30541462f3c1defa50b763322f971 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 2 Feb 2024 09:56:45 +0800 Subject: [PATCH] fix: drop db triggers which updates labels and highlights in library_item table for locking the table --- .../0160.do.drop_slow_db_triggers.sql | 11 +++++++++ .../0160.undo.drop_slow_db_triggers.sql | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 packages/db/migrations/0160.do.drop_slow_db_triggers.sql create mode 100755 packages/db/migrations/0160.undo.drop_slow_db_triggers.sql diff --git a/packages/db/migrations/0160.do.drop_slow_db_triggers.sql b/packages/db/migrations/0160.do.drop_slow_db_triggers.sql new file mode 100755 index 000000000..aa62a91dc --- /dev/null +++ b/packages/db/migrations/0160.do.drop_slow_db_triggers.sql @@ -0,0 +1,11 @@ +-- Type: DO +-- Name: drop_slow_db_triggers +-- Description: Drop some db triggers which are slow and have cascading effect + +BEGIN; + +DROP TRIGGER IF EXISTS library_item_labels_update ON omnivore.entity_labels; +DROP TRIGGER IF EXISTS library_item_highlight_annotations_update ON omnivore.highlight; +DROP TRIGGER IF EXISTS label_names_update ON omnivore.labels; + +COMMIT; diff --git a/packages/db/migrations/0160.undo.drop_slow_db_triggers.sql b/packages/db/migrations/0160.undo.drop_slow_db_triggers.sql new file mode 100755 index 000000000..bf24f3a0d --- /dev/null +++ b/packages/db/migrations/0160.undo.drop_slow_db_triggers.sql @@ -0,0 +1,23 @@ +-- Type: UNDO +-- Name: drop_slow_db_triggers +-- Description: Drop some db triggers which are slow and have cascading effect + +BEGIN; + +CREATE TRIGGER label_names_update +AFTER UPDATE ON omnivore.labels +FOR EACH ROW +WHEN (OLD.name <> NEW.name) +EXECUTE FUNCTION update_label_names(); + +CREATE TRIGGER library_item_highlight_annotations_update +AFTER INSERT OR UPDATE OR DELETE ON omnivore.highlight +FOR EACH ROW +EXECUTE FUNCTION update_library_item_highlight_annotations(); + +CREATE TRIGGER library_item_labels_update +AFTER INSERT OR UPDATE OR DELETE ON omnivore.entity_labels +FOR EACH ROW +EXECUTE FUNCTION update_library_item_labels(); + +COMMIT;