EXECUTE'INSERT INTO counter_cache (name, count) VALUES (''status_visibility_'||activity_visibility(NEW.actor,NEW.recipients,NEW.data)||''', 1) ON CONFLICT (name) DO UPDATE SET count = counter_cache.count + 1';
EXECUTE'INSERT INTO counter_cache (name, count) VALUES (''status_visibility_'||activity_visibility(NEW.actor,NEW.recipients,NEW.data)||''', 1) ON CONFLICT (name) DO UPDATE SET count = counter_cache.count + 1';
EXECUTE'update counter_cache SET count = counter_cache.count - 1 where count > 0 and name = ''status_visibility_'||activity_visibility(OLD.actor,OLD.recipients,OLD.data)||''';';
ENDIF;
RETURNNEW;
ELSIFTG_OP='DELETE'THEN
IFOLD.data->>'type'='Create'THEN
EXECUTE'update counter_cache SET count = counter_cache.count - 1 where count > 0 and name = ''status_visibility_'||activity_visibility(OLD.actor,OLD.recipients,OLD.data)||''';';