Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
done

- name: Run tests
run: go test -cover ./...
run: go test -count=1 -cover ./...


- name: Shutdown
Expand Down
1 change: 1 addition & 0 deletions api/dbv1/get_users.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/dbv1/queries/get_users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ current_user_subscribed_targets AS (
FROM subscriptions s
JOIN input_users i ON i.user_id = s.user_id
WHERE @my_id > 0
AND s.entity_type = 'User'
AND s.subscriber_id = @my_id
AND s.is_delete = false
GROUP BY s.user_id
Expand Down
11 changes: 8 additions & 3 deletions api/v1_events_followers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestEventFollowState_CountsOnlyLiveEventSubscriptions(t *testing.T) {
// A legacy user-type subscription with matching numeric id —
// must NOT be counted.
{
"subscriber_id": 2,
"subscriber_id": 5,
"user_id": 200,
"entity_type": "User",
"entity_id": nil,
Expand Down Expand Up @@ -514,7 +514,12 @@ func TestEventsFollowers_ReturnsOnlyLiveEventSubscribers(t *testing.T) {
app := emptyTestApp(t)

database.Seed(app.pool.Replicas[0], database.FixtureMap{
"users": testEventFollowersBaseUsers(),
"users": append(testEventFollowersBaseUsers(), map[string]any{
"user_id": 4,
"handle": "legacyfan",
"handle_lc": "legacyfan",
"name": "Legacy Fan",
}),
"tracks": {
{
"track_id": 1,
Expand Down Expand Up @@ -561,7 +566,7 @@ func TestEventsFollowers_ReturnsOnlyLiveEventSubscribers(t *testing.T) {
// Legacy user-type subscription with a colliding numeric id —
// must NOT show up.
{
"subscriber_id": 1,
"subscriber_id": 4,
"user_id": 200,
"entity_type": "User",
"entity_id": nil,
Expand Down
3 changes: 2 additions & 1 deletion api/v1_users_subscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func (app *ApiServer) v1UsersSubscribers(c *fiber.Ctx) error {
FROM
subscriptions
WHERE
user_id = @userId
entity_type = 'User'
AND user_id = @userId
AND is_current = true
AND is_delete = false
ORDER BY
Expand Down
13 changes: 8 additions & 5 deletions api/v1_users_subscribers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,27 @@ func TestUsersSubscribers(t *testing.T) {
{"user_id": 3, "handle": "subscriber3", "name": "Subscriber 3"},
{"user_id": 4, "handle": "deletedsub", "name": "Deleted Sub"},
{"user_id": 5, "handle": "oldsub", "name": "Old Sub"},
{"user_id": 6, "handle": "eventonlyfan", "name": "Event Only Fan"},
},
"aggregate_user": []map[string]any{
{"user_id": 1, "track_count": 1},
{"user_id": 2, "track_count": 1},
{"user_id": 3, "track_count": 1},
{"user_id": 4, "track_count": 1},
{"user_id": 5, "track_count": 1},
{"user_id": 6, "track_count": 1},
},
}

database.Seed(app.pool.Replicas[0], fixtures)
_, err := app.pool.Exec(t.Context(), `
INSERT INTO subscriptions (user_id, subscriber_id, is_current, is_delete, txhash)
INSERT INTO subscriptions (user_id, subscriber_id, is_current, is_delete, txhash, entity_type, entity_id)
VALUES
(1, 3, TRUE, FALSE, 'tx-sub-3'),
(1, 2, TRUE, FALSE, 'tx-sub-2'),
(1, 4, TRUE, TRUE, 'tx-sub-deleted'),
(1, 5, FALSE, FALSE, 'tx-sub-not-current')
(1, 3, TRUE, FALSE, 'tx-sub-3', 'User', NULL),
(1, 2, TRUE, FALSE, 'tx-sub-2', 'User', NULL),
(1, 4, TRUE, TRUE, 'tx-sub-deleted', 'User', NULL),
(1, 5, FALSE, FALSE, 'tx-sub-not-current', 'User', NULL),
(1, 6, TRUE, FALSE, 'tx-sub-event-collision', 'Event', 1)
`)
assert.NoError(t, err)

Expand Down
46 changes: 46 additions & 0 deletions api/v1_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"api.audius.co/api/dbv1"
"api.audius.co/database"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -87,6 +88,51 @@ func TestUserQuery(t *testing.T) {
}
}

func TestUserQuery_DoesCurrentUserSubscribeIgnoresEventSubscriptions(t *testing.T) {
app := emptyTestApp(t)

database.Seed(app.pool.Replicas[0], database.FixtureMap{
"users": []map[string]any{
{"user_id": 1, "handle": "artist", "name": "Artist"},
{"user_id": 2, "handle": "eventhost", "name": "Event Host"},
{"user_id": 3, "handle": "viewer", "name": "Viewer"},
},
"subscriptions": []map[string]any{
{
"subscriber_id": 3,
"user_id": 1,
"entity_type": "User",
"entity_id": nil,
"is_current": true,
"is_delete": false,
"txhash": "tx-user-sub",
},
{
"subscriber_id": 3,
"user_id": 2,
"entity_type": "Event",
"entity_id": 2,
"is_current": true,
"is_delete": false,
"txhash": "tx-event-collision",
},
},
})

users, err := app.queries.Users(t.Context(), dbv1.GetUsersParams{
MyID: 3,
Ids: []int32{1, 2},
})
assert.NoError(t, err)
require.Len(t, users, 2)
byID := map[int32]dbv1.User{}
for _, user := range users {
byID[user.UserID] = user
}
assert.True(t, byID[1].DoesCurrentUserSubscribe)
assert.False(t, byID[2].DoesCurrentUserSubscribe)
}

func TestGetUsers(t *testing.T) {
app := testAppWithFixtures(t)
var userResponse struct {
Expand Down
1 change: 1 addition & 0 deletions ddl/functions/handle_playlist.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ begin
from subscriptions
where is_current and
not is_delete and
entity_type = 'User' and
user_id=new.playlist_owner_id
) into subscriber_user_ids;
if array_length(subscriber_user_ids, 1) > 0 then
Expand Down
1 change: 1 addition & 0 deletions ddl/functions/handle_track.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ begin
from subscriptions
where is_current and
not is_delete and
entity_type = 'User' and
user_id=new.owner_id
) into subscriber_user_ids;

Expand Down
2 changes: 2 additions & 0 deletions sql/01_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3537,6 +3537,7 @@ begin
from subscriptions
where is_current and
not is_delete and
entity_type = 'User' and
user_id=new.playlist_owner_id
) into subscriber_user_ids;
if array_length(subscriber_user_ids, 1) > 0 then
Expand Down Expand Up @@ -4784,6 +4785,7 @@ begin
from subscriptions
where is_current and
not is_delete and
entity_type = 'User' and
user_id=new.owner_id
) into subscriber_user_ids;

Expand Down
Loading