Skip to content

Commit d52d762

Browse files
fixup(notifications): drop trending_playlist from handle_trending
The trending playlist reward (challenge_id 'tp') is being removed as a product feature, so handle_trending no longer needs to emit `trending_playlist` notifications. Scope: just this PR's trigger. PR #835's NewTrendingPlaylistProcessor + 'tp' catalog seed are still in place — harmless if the upstream feature stays inactive, can be torn out separately if desired. Changes: - handle_trending.sql: drop the 'tp' case from the type switch, WHEN clause, and data_jsonb branch. Trigger now only handles 'tt' and 'tut' (both tracks), so the entity_label variable goes away too. - trending_test.go: remove TestTrendingPlaylist_EmitsNotification. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3277ac0 commit d52d762

2 files changed

Lines changed: 22 additions & 77 deletions

File tree

ddl/functions/handle_trending.sql

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
-- handle_trending
22
--
3-
-- Emits one of `trending`, `trending_underground`, or `trending_playlist`
4-
-- when the trending challenge processor mints a user_challenges row for
5-
-- challenge_id 'tt' / 'tut' / 'tp'. These are the "your track is
6-
-- trending" notifications shown to the entity (track/playlist) owner.
3+
-- Emits a `trending` or `trending_underground` notification when the
4+
-- trending challenge processor mints a user_challenges row for
5+
-- challenge_id 'tt' / 'tut'. These are the "your track is trending"
6+
-- notifications shown to the track owner.
7+
--
8+
-- (Trending playlists — challenge_id 'tp' — were a product feature that
9+
-- has since been removed, so they're intentionally not handled here.
10+
-- handle_user_challenges.sql still excludes 'tp' from the
11+
-- claimable_reward path on line 14 for historical rows.)
712
--
813
-- Sibling of handle_user_challenges.sql which already emits the generic
9-
-- `challenge_reward` notification for all challenge completions (and
10-
-- skips the legacy `claimable_reward` for these three ids on line 14).
11-
-- This trigger is the type-specific layer that matches apps'
14+
-- `challenge_reward` notification for all challenge completions. This
15+
-- trigger is the type-specific layer that matches apps'
1216
-- index_trending.py notifications.
1317
--
1418
-- Specifier shape from jobs/challenges/trending.go is "<week>:<rank>"
@@ -22,18 +26,16 @@ declare
2226
entity_id_int bigint;
2327
notif_type text;
2428
trend_type text;
25-
entity_label text;
2629
ts_epoch bigint;
2730
data_jsonb jsonb;
2831
begin
29-
if new.challenge_id not in ('tt', 'tut', 'tp') then
32+
if new.challenge_id not in ('tt', 'tut') then
3033
return null;
3134
end if;
3235

3336
case new.challenge_id
34-
when 'tt' then notif_type := 'trending'; trend_type := 'TRACKS'; entity_label := 'track_id';
35-
when 'tut' then notif_type := 'trending_underground'; trend_type := 'UNDERGROUND_TRACKS'; entity_label := 'track_id';
36-
when 'tp' then notif_type := 'trending_playlist'; trend_type := 'PLAYLISTS'; entity_label := 'playlist_id';
37+
when 'tt' then notif_type := 'trending'; trend_type := 'TRACKS';
38+
when 'tut' then notif_type := 'trending_underground'; trend_type := 'UNDERGROUND_TRACKS';
3739
end case;
3840

3941
-- Specifier: "<YYYY-MM-DD>:<rank>"
@@ -69,21 +71,12 @@ begin
6971
-- the first insert — close enough to the recompute moment.
7072
ts_epoch := extract(epoch from new.completed_at)::bigint;
7173

72-
if new.challenge_id = 'tp' then
73-
data_jsonb := jsonb_build_object(
74-
'time_range', 'week',
75-
'genre', 'all',
76-
'rank', rank_int,
77-
'playlist_id', entity_id_int
78-
);
79-
else
80-
data_jsonb := jsonb_build_object(
81-
'time_range', 'week',
82-
'genre', 'all',
83-
'rank', rank_int,
84-
'track_id', entity_id_int
85-
);
86-
end if;
74+
data_jsonb := jsonb_build_object(
75+
'time_range', 'week',
76+
'genre', 'all',
77+
'rank', rank_int,
78+
'track_id', entity_id_int
79+
);
8780

8881
insert into notification
8982
(blocknumber, user_ids, timestamp, type, specifier, group_id, data)
@@ -96,7 +89,7 @@ begin
9689
entity_id_int::text,
9790
notif_type
9891
|| ':time_range:week:genre:all:rank:' || rank_int
99-
|| ':' || entity_label || ':' || entity_id_int
92+
|| ':track_id:' || entity_id_int
10093
|| ':timestamp:' || ts_epoch,
10194
data_jsonb
10295
)
@@ -119,7 +112,7 @@ do $$ begin
119112
-- fire AFTER INSERT triggers.
120113
create trigger on_trending_user_challenge
121114
after insert on user_challenges
122-
for each row when (new.challenge_id in ('tt', 'tut', 'tp'))
115+
for each row when (new.challenge_id in ('tt', 'tut'))
123116
execute procedure handle_trending();
124117
exception
125118
when others then null;

jobs/challenges/trending_test.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -156,51 +156,3 @@ func TestTrending_EmitsNotification(t *testing.T) {
156156
assert.Contains(t, nGroupID, ":rank:1:track_id:")
157157
assert.Contains(t, nGroupID, "trending:time_range:week:genre:all")
158158
}
159-
160-
// TestTrendingPlaylist_EmitsNotification — handle_trending fans out a
161-
// `trending_playlist` notification with playlist_id (not track_id) in
162-
// the data payload and group_id.
163-
func TestTrendingPlaylist_EmitsNotification(t *testing.T) {
164-
if time.Now().UTC().Weekday() != time.Friday {
165-
t.Skip("trending processor only runs on Fridays UTC")
166-
}
167-
pool := withChallengesDB(t)
168-
ctx := context.Background()
169-
now := time.Now()
170-
171-
database.Seed(pool, database.FixtureMap{
172-
"blocks": {{"blockhash": "blk_tpn", "number": 1}},
173-
"users": {{"user_id": 700, "wallet": "0x700"}},
174-
"playlists": {{
175-
"playlist_id": 7001,
176-
"playlist_owner_id": 700,
177-
"playlist_name": "P",
178-
"blocknumber": 1,
179-
"created_at": now,
180-
}},
181-
})
182-
183-
_, err := pool.Exec(ctx, `
184-
INSERT INTO playlist_trending_scores (playlist_id, type, version, time_range, score, created_at)
185-
VALUES (7001, 'PLAYLISTS', 'pnagD', 'week', 999.0, now())
186-
`)
187-
require.NoError(t, err)
188-
189-
runProcessor(t, pool, NewTrendingPlaylistProcessor())
190-
191-
var nGroupID string
192-
var nData []byte
193-
err = pool.QueryRow(ctx, `
194-
SELECT group_id, data
195-
FROM notification
196-
WHERE type = 'trending_playlist' AND user_ids = ARRAY[700]
197-
`).Scan(&nGroupID, &nData)
198-
require.NoError(t, err, "expected trending_playlist notif")
199-
200-
var data map[string]any
201-
require.NoError(t, json.Unmarshal(nData, &data))
202-
assert.EqualValues(t, 7001, data["playlist_id"])
203-
assert.NotContains(t, data, "track_id")
204-
assert.Contains(t, nGroupID, ":playlist_id:7001:")
205-
assert.Contains(t, nGroupID, "trending_playlist:time_range:week:genre:all")
206-
}

0 commit comments

Comments
 (0)