Skip to content

Commit 90c264a

Browse files
committed
playlist: move my_follows to cte
1 parent 64b2275 commit 90c264a

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

api/dbv1/get_playlists.sql.go

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/dbv1/queries/get_playlists.sql

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
-- name: GetPlaylists :many
2+
WITH my_follows AS (
3+
SELECT
4+
followee_user_id as user_id,
5+
follower_count
6+
FROM follows
7+
JOIN aggregate_user ON followee_user_id = user_id
8+
WHERE @my_id > 0
9+
AND follower_user_id = @my_id
10+
AND follows.is_delete = false
11+
ORDER BY follower_count DESC
12+
LIMIT 5000
13+
)
214
SELECT
315
-- artwork
416
p.description,
@@ -64,8 +76,7 @@ SELECT
6476
FROM (
6577
SELECT user_id, repost_item_id, reposts.created_at
6678
FROM reposts
67-
JOIN follows ON followee_user_id = reposts.user_id AND follower_user_id = @my_id
68-
JOIN aggregate_user USING (user_id)
79+
JOIN my_follows USING (user_id)
6980
WHERE repost_item_id = p.playlist_id
7081
AND repost_type != 'track'
7182
AND reposts.is_delete = false
@@ -86,8 +97,7 @@ SELECT
8697
FROM (
8798
SELECT user_id, save_item_id, saves.created_at
8899
FROM saves
89-
JOIN follows ON followee_user_id = saves.user_id AND follower_user_id = @my_id
90-
JOIN aggregate_user USING (user_id)
100+
JOIN my_follows USING (user_id)
91101
WHERE save_item_id = p.playlist_id
92102
AND save_type != 'track'
93103
AND saves.is_delete = false

0 commit comments

Comments
 (0)