diff --git a/query/getters.go b/query/getters.go index fbff8465..2afdee49 100644 --- a/query/getters.go +++ b/query/getters.go @@ -26,6 +26,12 @@ func FlushGettersCache() { immutableCache.Flush() } +// InvalidateCacheByID deletes a single item from the getters cache +func InvalidateCacheByID[T any](id string) { + key := cacheKey[T]("id", id) + getterCache.Delete(key) +} + type GetterOption uint8 const ( diff --git a/views/033_table_activity.sql b/views/033_table_activity.sql index 7bf75078..1c7d3e84 100644 --- a/views/033_table_activity.sql +++ b/views/033_table_activity.sql @@ -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 $$; \ No newline at end of file + EXECUTE PROCEDURE notify_table_updates_and_deletes()', table_name); + END LOOP; +END +$$; +