mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
- Couple streaks with milestone notifications - Scheduled pack releases with admin UI - Notification preferences screen - Refactored profile settings screens - Partner activity notifications
29 lines
765 B
PL/PgSQL
29 lines
765 B
PL/PgSQL
-- Expose per-feature opt-in counts for admins
|
|
|
|
CREATE OR REPLACE FUNCTION public.get_feature_interest_counts()
|
|
RETURNS TABLE (
|
|
feature_name TEXT,
|
|
opt_in_count BIGINT,
|
|
opt_in_count_last_7_days BIGINT
|
|
)
|
|
LANGUAGE plpgsql
|
|
SECURITY DEFINER
|
|
SET search_path = 'public'
|
|
AS $$
|
|
BEGIN
|
|
IF NOT has_permission('view_users') THEN
|
|
RAISE EXCEPTION 'Access denied';
|
|
END IF;
|
|
|
|
RETURN QUERY
|
|
SELECT
|
|
fi.feature_name,
|
|
COUNT(*)::BIGINT AS opt_in_count,
|
|
COUNT(*) FILTER (WHERE fi.created_at >= now() - interval '7 days')::BIGINT AS opt_in_count_last_7_days
|
|
FROM public.feature_interests fi
|
|
GROUP BY fi.feature_name
|
|
ORDER BY opt_in_count DESC, fi.feature_name ASC;
|
|
END;
|
|
$$;
|
|
GRANT EXECUTE ON FUNCTION public.get_feature_interest_counts() TO authenticated;
|