Skip to content

Commit

Permalink
[bugfix] Sort follows chronologically (#2801)
Browse files Browse the repository at this point in the history
The id on the follows table is not a ULID, but a random ID. Sorting on
them results in a completely random order. Instead, sort on created_at,
which sould result in a stable and intended sort order.

Fixes: #2769

Co-authored-by: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>
  • Loading branch information
daenney and NyaaaWhatsUpDoc committed Apr 3, 2024
1 parent 15ede4c commit 8ed1b81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions internal/db/bundb/relationship.go
Expand Up @@ -331,7 +331,7 @@ func newSelectFollows(db *bun.DB, accountID string) *bun.SelectQuery {
Table("follows").
Column("id").
Where("? = ?", bun.Ident("account_id"), accountID).
OrderExpr("? DESC", bun.Ident("id"))
OrderExpr("? DESC", bun.Ident("created_at"))
}

// newSelectLocalFollows returns a new select query for all rows in the follows table with
Expand All @@ -349,7 +349,7 @@ func newSelectLocalFollows(db *bun.DB, accountID string) *bun.SelectQuery {
Column("id").
Where("? IS NULL", bun.Ident("domain")),
).
OrderExpr("? DESC", bun.Ident("id"))
OrderExpr("? DESC", bun.Ident("created_at"))
}

// newSelectFollowers returns a new select query for all rows in the follows table with target_account_id = accountID.
Expand All @@ -358,7 +358,7 @@ func newSelectFollowers(db *bun.DB, accountID string) *bun.SelectQuery {
Table("follows").
Column("id").
Where("? = ?", bun.Ident("target_account_id"), accountID).
OrderExpr("? DESC", bun.Ident("id"))
OrderExpr("? DESC", bun.Ident("created_at"))
}

// newSelectLocalFollowers returns a new select query for all rows in the follows table with
Expand All @@ -376,7 +376,7 @@ func newSelectLocalFollowers(db *bun.DB, accountID string) *bun.SelectQuery {
Column("id").
Where("? IS NULL", bun.Ident("domain")),
).
OrderExpr("? DESC", bun.Ident("id"))
OrderExpr("? DESC", bun.Ident("created_at"))
}

// newSelectBlocks returns a new select query for all rows in the blocks table with account_id = accountID.
Expand Down
4 changes: 2 additions & 2 deletions internal/federation/federatingdb/following_test.go
Expand Up @@ -47,8 +47,8 @@ func (suite *FollowingTestSuite) TestGetFollowing() {
suite.Equal(`{
"@context": "https://www.w3.org/ns/activitystreams",
"items": [
"http://localhost:8080/users/1happyturtle",
"http://localhost:8080/users/admin"
"http://localhost:8080/users/admin",
"http://localhost:8080/users/1happyturtle"
],
"type": "Collection"
}`, string(fJson))
Expand Down

0 comments on commit 8ed1b81

Please sign in to comment.