From c08282a36ff1bbf0ed9cbed48a0a89243adff1fc Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 2 Sep 2025 11:08:01 +0000 Subject: [PATCH] improve the notify mechanism for resource change --- ...resource_cache_on_variable_change.down.sql | 1 + ...y_resource_cache_on_variable_change.up.sql | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 backend/migrations/20250902085503_notify_resource_cache_on_variable_change.down.sql create mode 100644 backend/migrations/20250902085503_notify_resource_cache_on_variable_change.up.sql diff --git a/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.down.sql b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.up.sql b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.up.sql new file mode 100644 index 0000000000..1ee9d2d43b --- /dev/null +++ b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.up.sql @@ -0,0 +1,23 @@ +-- Add up migration script here +CREATE OR REPLACE FUNCTION notify_var_resource_cache_change() +RETURNS TRIGGER AS $$ +BEGIN + IF TG_TABLE_NAME = 'variable' THEN + PERFORM pg_notify('var_cache_invalidation', + json_build_object( + 'workspace_id', COALESCE(NEW.workspace_id, OLD.workspace_id), + 'path', COALESCE(NEW.path, OLD.path), + 'operation', TG_OP + )::text + ); + END IF; + PERFORM pg_notify('resource_cache_invalidation', + json_build_object( + 'workspace_id', COALESCE(NEW.workspace_id, OLD.workspace_id), + 'path', COALESCE(NEW.path, OLD.path), + 'operation', TG_OP + )::text + ); + RETURN COALESCE(NEW, OLD); +END; +$$ LANGUAGE plpgsql; \ No newline at end of file