mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-26 03:23:32 -06:00
fix public timeline bug (#150)
This commit is contained in:
parent
2dc9fc1626
commit
ddc120d5e6
18 changed files with 162 additions and 79 deletions
|
|
@ -110,7 +110,7 @@ func (a *accountDB) GetInstanceAccount(ctx context.Context, domain string) (*gts
|
|||
} else {
|
||||
q = q.
|
||||
Where("account.username = ?", domain).
|
||||
Where("? IS NULL", bun.Ident("domain"))
|
||||
WhereGroup(" AND ", whereEmptyOrNull("domain"))
|
||||
}
|
||||
|
||||
err := processErrorResponse(q.Scan(ctx))
|
||||
|
|
@ -172,7 +172,7 @@ func (a *accountDB) GetLocalAccountByUsername(ctx context.Context, username stri
|
|||
|
||||
q := a.newAccountQ(account).
|
||||
Where("username = ?", username).
|
||||
Where("? IS NULL", bun.Ident("domain"))
|
||||
WhereGroup(" AND ", whereEmptyOrNull("domain"))
|
||||
|
||||
err := processErrorResponse(q.Scan(ctx))
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ func (a *accountDB) GetAccountStatuses(ctx context.Context, accountID string, li
|
|||
}
|
||||
|
||||
if excludeReplies {
|
||||
q = q.Where("? IS NULL", bun.Ident("in_reply_to_id"))
|
||||
q = q.WhereGroup(" AND ", whereEmptyOrNull("in_reply_to_id"))
|
||||
}
|
||||
|
||||
if pinnedOnly {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string,
|
|||
err = a.conn.NewSelect().
|
||||
Model(acct).
|
||||
Where("username = ?", username).
|
||||
Where("? IS NULL", bun.Ident("domain")).
|
||||
WhereGroup(" AND ", whereEmptyOrNull("domain")).
|
||||
Scan(ctx)
|
||||
if err != nil {
|
||||
// we just don't have an account yet create one
|
||||
|
|
@ -181,7 +181,7 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error {
|
|||
NewSelect().
|
||||
Model(>smodel.Account{}).
|
||||
Where("username = ?", username).
|
||||
Where("? IS NULL", bun.Ident("domain"))
|
||||
WhereGroup(" AND ", whereEmptyOrNull("domain"))
|
||||
count, err := existsQ.Count(ctx)
|
||||
if err != nil && count == 1 {
|
||||
a.log.Infof("instance account %s already exists", username)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,13 @@ func (suite *BasicTestSuite) TestGetAccountByID() {
|
|||
suite.NoError(err)
|
||||
}
|
||||
|
||||
func (suite *BasicTestSuite) TestGetAllStatuses() {
|
||||
s := []*gtsmodel.Status{}
|
||||
err := suite.db.GetAll(context.Background(), &s)
|
||||
suite.NoError(err)
|
||||
suite.Len(s, 12)
|
||||
}
|
||||
|
||||
func TestBasicTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(BasicTestSuite))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func (i *instanceDB) CountInstanceUsers(ctx context.Context, domain string) (int
|
|||
|
||||
if domain == i.config.Host {
|
||||
// if the domain is *this* domain, just count where the domain field is null
|
||||
q = q.Where("? IS NULL", bun.Ident("domain"))
|
||||
q = q.WhereGroup(" AND ", whereEmptyOrNull("domain"))
|
||||
} else {
|
||||
q = q.Where("domain = ?", domain)
|
||||
}
|
||||
|
|
@ -83,7 +83,9 @@ func (i *instanceDB) CountInstanceDomains(ctx context.Context, domain string) (i
|
|||
if domain == i.config.Host {
|
||||
// if the domain is *this* domain, just count other instances it knows about
|
||||
// exclude domains that are blocked
|
||||
q = q.Where("domain != ?", domain).Where("? IS NULL", bun.Ident("suspended_at"))
|
||||
q = q.
|
||||
Where("domain != ?", domain).
|
||||
Where("? IS NULL", bun.Ident("suspended_at"))
|
||||
} else {
|
||||
// TODO: implement federated domain counting properly for remote domains
|
||||
return 0, nil
|
||||
|
|
|
|||
|
|
@ -294,18 +294,10 @@ func (r *relationshipDB) GetAccountFollowedBy(ctx context.Context, accountID str
|
|||
Model(&follows)
|
||||
|
||||
if localOnly {
|
||||
// for local accounts let's get where domain is null OR where domain is an empty string, just to be safe
|
||||
whereGroup := func(q *bun.SelectQuery) *bun.SelectQuery {
|
||||
q = q.
|
||||
WhereOr("? IS NULL", bun.Ident("a.domain")).
|
||||
WhereOr("a.domain = ?", "")
|
||||
return q
|
||||
}
|
||||
|
||||
q = q.ColumnExpr("follow.*").
|
||||
Join("JOIN accounts AS a ON follow.account_id = TEXT(a.id)").
|
||||
Where("follow.target_account_id = ?", accountID).
|
||||
WhereGroup(" AND ", whereGroup)
|
||||
WhereGroup(" AND ", whereEmptyOrNull("a.domain"))
|
||||
} else {
|
||||
q = q.Where("target_account_id = ?", accountID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ func (t *timelineDB) GetPublicTimeline(ctx context.Context, accountID string, ma
|
|||
NewSelect().
|
||||
Model(&statuses).
|
||||
Where("visibility = ?", gtsmodel.VisibilityPublic).
|
||||
Where("? IS NULL", bun.Ident("in_reply_to_id")).
|
||||
Where("? IS NULL", bun.Ident("in_reply_to_uri")).
|
||||
Where("? IS NULL", bun.Ident("boost_of_id")).
|
||||
WhereGroup(" AND ", whereEmptyOrNull("in_reply_to_id")).
|
||||
WhereGroup(" AND ", whereEmptyOrNull("in_reply_to_uri")).
|
||||
WhereGroup(" AND ", whereEmptyOrNull("boost_of_id")).
|
||||
Order("status.id DESC")
|
||||
|
||||
if maxID != "" {
|
||||
|
|
|
|||
68
internal/db/bundb/timeline_test.go
Normal file
68
internal/db/bundb/timeline_test.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
GoToSocial
|
||||
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bundb_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
type TimelineTestSuite struct {
|
||||
BunDBStandardTestSuite
|
||||
}
|
||||
|
||||
func (suite *TimelineTestSuite) SetupSuite() {
|
||||
suite.testTokens = testrig.NewTestTokens()
|
||||
suite.testClients = testrig.NewTestClients()
|
||||
suite.testApplications = testrig.NewTestApplications()
|
||||
suite.testUsers = testrig.NewTestUsers()
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
suite.testAttachments = testrig.NewTestAttachments()
|
||||
suite.testStatuses = testrig.NewTestStatuses()
|
||||
suite.testTags = testrig.NewTestTags()
|
||||
suite.testMentions = testrig.NewTestMentions()
|
||||
}
|
||||
|
||||
func (suite *TimelineTestSuite) SetupTest() {
|
||||
suite.config = testrig.NewTestConfig()
|
||||
suite.db = testrig.NewTestDB()
|
||||
suite.log = testrig.NewTestLog()
|
||||
|
||||
testrig.StandardDBSetup(suite.db, suite.testAccounts)
|
||||
}
|
||||
|
||||
func (suite *TimelineTestSuite) TearDownTest() {
|
||||
testrig.StandardDBTeardown(suite.db)
|
||||
}
|
||||
|
||||
func (suite *TimelineTestSuite) TestGetPublicTimeline() {
|
||||
viewingAccount := suite.testAccounts["local_account_1"]
|
||||
|
||||
s, err := suite.db.GetPublicTimeline(context.Background(), viewingAccount.ID, "", "", "", 20, false)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Len(s, 6)
|
||||
}
|
||||
|
||||
func TestTimelineTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(TimelineTestSuite))
|
||||
}
|
||||
|
|
@ -76,3 +76,17 @@ func notExists(ctx context.Context, q *bun.SelectQuery) (bool, db.Error) {
|
|||
|
||||
return notExists, nil
|
||||
}
|
||||
|
||||
// whereEmptyOrNull is a convenience function to return a bun WhereGroup that specifies
|
||||
// that the given column should be EITHER an empty string OR null.
|
||||
//
|
||||
// Use it as follows:
|
||||
//
|
||||
// q = q.WhereGroup(" AND ", whereEmptyOrNull("whatever_column"))
|
||||
func whereEmptyOrNull(column string) func(*bun.SelectQuery) *bun.SelectQuery {
|
||||
return func(q *bun.SelectQuery) *bun.SelectQuery {
|
||||
return q.
|
||||
WhereOr("? IS NULL", bun.Ident(column)).
|
||||
WhereOr("? = ''", bun.Ident(column))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue