feat(top-tags): surface top tags and genres across relevant views

This commit is contained in:
Cory Dransfeldt 2025-05-15 08:54:59 -07:00
parent e133fd959d
commit 4f15e88074
No known key found for this signature in database
10 changed files with 94 additions and 9 deletions

View file

@ -0,0 +1,37 @@
CREATE OR REPLACE FUNCTION get_top_tag_groups()
RETURNS JSON AS $$
BEGIN
RETURN json_build_object(
'tags', (
SELECT json_agg(t) FROM (
SELECT tag, COUNT(*) AS usage_count
FROM optimized_tagged_content
WHERE type IN ('article', 'link')
GROUP BY tag
ORDER BY usage_count DESC
LIMIT 10
) t
),
'watching_genres', (
SELECT json_agg(t) FROM (
SELECT tag, COUNT(*) AS usage_count
FROM optimized_tagged_content
WHERE type IN ('tv', 'movies')
GROUP BY tag
ORDER BY usage_count DESC
LIMIT 10
) t
),
'books_genres', (
SELECT json_agg(t) FROM (
SELECT tag, COUNT(*) AS usage_count
FROM optimized_tagged_content
WHERE type = 'books'
GROUP BY tag
ORDER BY usage_count DESC
LIMIT 10
) t
)
);
END;
$$ LANGUAGE plpgsql STABLE;