Skip to content

Commit

Permalink
feat: table playbook activity pg notify
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 5, 2024
1 parent 125fa6c commit c727a50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
6 changes: 6 additions & 0 deletions query/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func FlushGettersCache() {
immutableCache.Flush()
}

// GetterCacheDeleteByID deletes a single item from the getters cache
func GetterCacheDeleteByID[T any](id string) {
key := cacheKey[T]("id", id)
getterCache.Delete(key)
}

type GetterOption uint8

const (
Expand Down
41 changes: 23 additions & 18 deletions views/033_table_activity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,36 @@ DROP TRIGGER IF EXISTS handle_notifications_updates_deletes_trigger ON notificat
DROP FUNCTION IF EXISTS handle_notifications_updates_deletes;

-- Notify on any updates/deletes on these tables
CREATE OR REPLACE FUNCTION notify_table_updates_and_deletes()
RETURNS TRIGGER AS $$
CREATE OR REPLACE FUNCTION notify_table_updates_and_deletes ()
RETURNS TRIGGER
AS $$
BEGIN
IF TG_OP = 'DELETE' THEN
PERFORM pg_notify('table_activity', TG_TABLE_NAME || ' ' || OLD.id);
PERFORM
pg_notify('table_activity', TG_TABLE_NAME || ' ' || OLD.id);
ELSE
PERFORM pg_notify('table_activity', TG_TABLE_NAME || ' ' || NEW.id);
PERFORM
pg_notify('table_activity', TG_TABLE_NAME || ' ' || NEW.id);
END IF;

RETURN NULL;
END
$$ LANGUAGE plpgsql;
$$
LANGUAGE plpgsql;

DO $$
DECLARE
table_name TEXT;
BEGIN
FOR table_name IN SELECT unnest(ARRAY['notifications', 'permissions', 'teams'])
LOOP
EXECUTE format('
DO $$
DECLARE
table_name text;
BEGIN
FOR table_name IN
SELECT
unnest(ARRAY['notifications', 'playbooks', 'permissions', 'teams'])
LOOP
EXECUTE format('
CREATE OR REPLACE TRIGGER notify_updates_and_deletes
AFTER INSERT OR UPDATE OR DELETE ON %I
FOR EACH ROW
EXECUTE PROCEDURE notify_table_updates_and_deletes()',
table_name
);
END LOOP;
END $$;
EXECUTE PROCEDURE notify_table_updates_and_deletes()', table_name);
END LOOP;
END
$$;

0 comments on commit c727a50

Please sign in to comment.