Skip to content

Commit c0ab7f4

Browse files
committed
Hide deleted/unavailable tracks from all list endpoints
Deleted tracks (is_delete=true) are now always excluded from all list endpoints. Unavailable tracks (is_available=false) are hidden for everyone except the track owner, who can still see them for tombstone handling on the UI. Direct track links continue to return tombstone responses as before. Changes across 14 endpoint files: - User-facing endpoints (history, tracks, library, favorites, playlist tracks): filter is_delete=false, is_available with owner exception, and users.is_deactivated=false where applicable - Discovery endpoints (feed, recommended, remixes, best selling, trending playlists, stems, remixing, subsequent): add missing is_available=true and is_delete=false filters https://claude.ai/code/session_01A9o7GfeC7sitKmWSvw2pzZ
1 parent 0247f66 commit c0ab7f4

14 files changed

Lines changed: 47 additions & 16 deletions

api/v1_explore_best_selling.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (app *ApiServer) v1ExploreBestSelling(c *fiber.Ctx) error {
5959
AND t.is_delete = false
6060
AND t.is_current = true
6161
AND t.is_unlisted = false
62+
AND t.is_available = true
6263
6364
UNION ALL
6465

api/v1_playlist_tracks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func (app *ApiServer) v1PlaylistTracks(c *fiber.Ctx) error {
3030
"p.playlist_id = @playlistId",
3131
"t.is_delete = false",
3232
"t.is_current = true",
33+
"(t.is_available = true OR t.owner_id = @myId)",
3334
}
3435
if excludeGated {
3536
filters = append(filters, "t.is_stream_gated != true")
@@ -47,6 +48,7 @@ func (app *ApiServer) v1PlaylistTracks(c *fiber.Ctx) error {
4748

4849
rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{
4950
"playlistId": playlistId,
51+
"myId": myId,
5052
})
5153
if err != nil {
5254
return err

api/v1_playlists_trending.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (app *ApiServer) v1PlaylistsTrending(c *fiber.Ctx) error {
6262
pt.is_removed = false
6363
AND t.is_delete = false
6464
AND t.is_current = true
65+
AND t.is_available = true
6566
AND t.stem_of IS NULL
6667
AND (t.access_authorities IS NULL
6768
OR (COALESCE(@authed_wallet, '') <> ''

api/v1_track_remixes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (app *ApiServer) v1TrackRemixes(c *fiber.Ctx) error {
4646
"t.is_current = true",
4747
"t.is_delete = false",
4848
"t.is_unlisted = false",
49+
"t.is_available = true",
4950
}
5051

5152
if params.OnlyContestEntries {

api/v1_track_remixing.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func (app *ApiServer) v1TrackRemixing(c *fiber.Ctx) error {
2525
JOIN remixes r ON r.parent_track_id = pt.track_id AND r.child_track_id = @trackId
2626
JOIN tracks ct ON ct.track_id = @trackId AND ct.is_current = true AND ct.is_stream_gated = false
2727
WHERE pt.is_current = true
28+
AND pt.is_delete = false
29+
AND pt.is_available = true
2830
AND pt.is_unlisted = false
2931
ORDER BY pt.created_at DESC, pt.track_id DESC
3032
LIMIT @limit OFFSET @offset

api/v1_track_stems.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ func (app *ApiServer) v1TrackStems(c *fiber.Ctx) error {
3131
JOIN tracks parent ON parent.track_id = s.parent_track_id
3232
WHERE t.is_current = true
3333
AND t.is_delete = false
34+
AND t.is_available = true
3435
AND s.parent_track_id = @track_id
3536
AND parent.is_delete = false
37+
AND parent.is_available = true
3638
`
3739

3840
rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{

api/v1_track_subsequent.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,19 @@ func (app *ApiServer) v1TrackSubsequent(c *fiber.Ctx) error {
4040
FROM tracks
4141
WHERE is_current = true AND created_at = (SELECT created_at from current_track)
4242
AND track_id > @trackId
43+
AND is_delete = false
44+
AND is_available = true
45+
AND is_unlisted = false
4346
ORDER BY track_id ASC
4447
LIMIT @limit
4548
),
4649
future_tracks AS (
4750
SELECT track_id, created_at
4851
FROM tracks
4952
WHERE is_current = true AND created_at > (SELECT created_at from current_track)
53+
AND is_delete = false
54+
AND is_available = true
55+
AND is_unlisted = false
5056
ORDER by created_at ASC, track_ID ASC
5157
LIMIT @limit
5258
),

api/v1_users_favorites.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,32 @@ func (app *ApiServer) v1UsersFavorites(c *fiber.Ctx) error {
2525
return err
2626
}
2727

28+
myId := app.getMyId(c)
29+
2830
sql := `
2931
SELECT
3032
save_item_id,
3133
'SaveType.' || save_type as save_item_type, -- concat in "SaveType" to match sqlalchemy bs
32-
user_id,
33-
created_at
34+
saves.user_id,
35+
saves.created_at
3436
FROM saves
35-
WHERE user_id = @userId
36-
AND is_delete = false
37-
AND is_current = true
37+
JOIN tracks ON tracks.track_id = saves.save_item_id
38+
JOIN users ON users.user_id = tracks.owner_id
39+
WHERE saves.user_id = @userId
40+
AND saves.is_delete = false
41+
AND saves.is_current = true
3842
AND save_type = 'track'
39-
ORDER BY blocknumber, save_item_id desc
43+
AND tracks.is_delete = false
44+
AND (tracks.is_available = true OR tracks.owner_id = @myId)
45+
AND users.is_deactivated = false
46+
ORDER BY saves.blocknumber, save_item_id desc
4047
LIMIT @limit
4148
OFFSET @offset
4249
`
4350

4451
rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{
4552
"userId": app.getUserId(c),
53+
"myId": myId,
4654
"limit": params.Limit,
4755
"offset": params.Offset,
4856
})

api/v1_users_feed.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (app *ApiServer) v1UsersFeed(c *fiber.Ctx) error {
9191
AND created_at >= @before::timestamp - INTERVAL '1 YEAR'
9292
AND is_unlisted = false
9393
AND is_delete = false
94+
AND is_available = true
9495
AND stem_of is null
9596
AND (access_authorities IS NULL
9697
OR (COALESCE(@authed_wallet, '') <> ''

api/v1_users_history.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,20 @@ func (app *ApiServer) v1UsersHistory(c *fiber.Ctx) error {
6262
class = "track_activity_full"
6363
}
6464

65-
filters := []string{}
65+
filters := []string{
66+
"tracks.is_delete = false",
67+
"(tracks.is_available = true OR tracks.owner_id = @myId)",
68+
"users.is_deactivated = false",
69+
}
6670
if params.Query != "" {
67-
filters = append(filters, "tracks.title ILIKE '%' || @query || '%' OR users.name ILIKE '%' || @query || '%'")
71+
filters = append(filters, "(tracks.title ILIKE '%' || @query || '%' OR users.name ILIKE '%' || @query || '%')")
6872
}
6973

7074
if myId == 0 || myId != userId {
7175
filters = append(filters, "tracks.is_unlisted = false")
7276
}
7377

74-
filterString := ""
75-
if len(filters) > 0 {
76-
filterString = "WHERE " + strings.Join(filters, " AND ")
77-
}
78+
filterString := "WHERE " + strings.Join(filters, " AND ")
7879

7980
sql := `
8081
WITH history AS (
@@ -101,6 +102,7 @@ func (app *ApiServer) v1UsersHistory(c *fiber.Ctx) error {
101102
`
102103
rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{
103104
"userId": userId,
105+
"myId": myId,
104106
"limit": params.Limit,
105107
"offset": params.Offset,
106108
"query": params.Query,

0 commit comments

Comments
 (0)