-
Notifications
You must be signed in to change notification settings - Fork 1
Filter tracks with access_authorities #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dbd51bd
8afaaf0
8074437
c8e7208
b385ed0
e0188c6
7b672af
727b196
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| -- name: GetTrackIdsByISRC :many | ||
| SELECT track_id | ||
| FROM tracks | ||
| WHERE isrc = ANY(@isrcs::text[]); | ||
| WHERE isrc = ANY(@isrcs::text[]) | ||
| AND access_authorities IS NULL; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMetricsGenres(t *testing.T) { | ||
|
|
@@ -41,3 +43,52 @@ func TestMetricsGenres(t *testing.T) { | |
| } | ||
|
|
||
| } | ||
|
|
||
| func TestMetricsGenresExcludesAccessAuthoritiesTracks(t *testing.T) { | ||
| app := testAppWithFixtures(t) | ||
| ctx := context.Background() | ||
| require.NotNil(t, app.writePool, "test requires write pool") | ||
|
|
||
| // Get baseline Electronic count (use epoch so all fixture tracks are included) | ||
| url := fmt.Sprintf("/v1/metrics/genres?start_time=%d", 0) | ||
| var before struct { | ||
| Data []struct { | ||
| Name string `json:"name"` | ||
| Count int64 `json:"count"` | ||
| } | ||
|
Comment on lines
+54
to
+58
|
||
| } | ||
| status, _ := testGet(t, app, url, &before) | ||
| require.Equal(t, 200, status) | ||
|
|
||
| var electronicCountBefore int64 | ||
| for _, g := range before.Data { | ||
| if g.Name == "Electronic" { | ||
| electronicCountBefore = g.Count | ||
| break | ||
| } | ||
| } | ||
| require.Greater(t, electronicCountBefore, int64(0), "fixtures should have Electronic tracks") | ||
|
|
||
| // Gate one Electronic track (track 100 is Electronic) | ||
| _, err := app.writePool.Exec(ctx, `UPDATE tracks SET access_authorities = ARRAY['0xgate']::text[] WHERE track_id = 100 AND is_current = true`) | ||
| require.NoError(t, err) | ||
|
|
||
| var after struct { | ||
| Data []struct { | ||
| Name string `json:"name"` | ||
| Count int64 `json:"count"` | ||
| } | ||
| } | ||
| status, _ = testGet(t, app, url, &after) | ||
| require.Equal(t, 200, status) | ||
|
|
||
| var electronicCountAfter int64 | ||
| for _, g := range after.Data { | ||
| if g.Name == "Electronic" { | ||
| electronicCountAfter = g.Count | ||
| break | ||
| } | ||
| } | ||
| assert.Equal(t, electronicCountBefore-1, electronicCountAfter, "genre count must exclude access_authorities tracks") | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetTracksfilters out gated tracks witht.access_authorities IS NULL, but it doesn’t filtert.is_current = true. Sincetracksis versioned (PK includestxhashand hasis_current), a track whose current row is gated could still be returned via an olderis_current=falserow whereaccess_authoritiesis NULL. AddAND t.is_current = true(and ensure joins/selects are consistent) so the exclusion can’t be bypassed via historical rows.