mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 00:02:25 -05:00
[performance] refactoring + add fave / follow / request / visibility caching (#1607)
* refactor visibility checking, add caching for visibility
* invalidate visibility cache items on account / status deletes
* fix requester ID passed to visibility cache nil ptr
* de-interface caches, fix home / public timeline caching + visibility
* finish adding code comments for visibility filter
* fix angry goconst linter warnings
* actually finish adding filter visibility code comments for timeline functions
* move home timeline status author check to after visibility
* remove now-unused code
* add more code comments
* add TODO code comment, update printed cache start names
* update printed cache names on stop
* start adding separate follow(request) delete db functions, add specific visibility cache tests
* add relationship type caching
* fix getting local account follows / followed-bys, other small codebase improvements
* simplify invalidation using cache hooks, add more GetAccountBy___() functions
* fix boosting to return 404 if not boostable but no error (to not leak status ID)
* remove dead code
* improved placement of cache invalidation
* update license headers
* add example follow, follow-request config entries
* add example visibility cache configuration to config file
* use specific PutFollowRequest() instead of just Put()
* add tests for all GetAccountBy()
* add GetBlockBy() tests
* update block to check primitive fields
* update and finish adding Get{Account,Block,Follow,FollowRequest}By() tests
* fix copy-pasted code
* update envparsing test
* whitespace
* fix bun struct tag
* add license header to gtscontext
* fix old license header
* improved error creation to not use fmt.Errorf() when not needed
* fix various rebase conflicts, fix account test
* remove commented-out code, fix-up mention caching
* fix mention select bun statement
* ensure mention target account populated, pass in context to customrenderer logging
* remove more uncommented code, fix typeutil test
* add statusfave database model caching
* add status fave cache configuration
* add status fave cache example config
* woops, catch missed error. nice catch linter!
* add back testrig panic on nil db
* update example configuration to match defaults, slight tweak to cache configuration defaults
* update envparsing test with new defaults
* fetch followingget to use the follow target account
* use accounnt.IsLocal() instead of empty domain check
* use constants for the cache visibility type check
* use bun.In() for notification type restriction in db query
* include replies when fetching PublicTimeline() (to account for single-author threads in Visibility{}.StatusPublicTimelineable())
* use bun query building for nested select statements to ensure working with postgres
* update public timeline future status checks to match visibility filter
* same as previous, for home timeline
* update public timeline tests to dynamically check for appropriate statuses
* migrate accounts to allow unique constraint on public_key
* provide minimal account with publicKey
---------
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
This commit is contained in:
parent
7d09863393
commit
de6e3e5f2a
100 changed files with 4423 additions and 2367 deletions
|
|
@ -19,17 +19,359 @@ package bundb_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
)
|
||||
|
||||
type RelationshipTestSuite struct {
|
||||
BunDBStandardTestSuite
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetBlockBy() {
|
||||
t := suite.T()
|
||||
|
||||
// Create a new context for this test.
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
// Sentinel error to mark avoiding a test case.
|
||||
sentinelErr := errors.New("sentinel")
|
||||
|
||||
// isEqual checks if 2 block models are equal.
|
||||
isEqual := func(b1, b2 gtsmodel.Block) bool {
|
||||
// Clear populated sub-models.
|
||||
b1.Account = nil
|
||||
b2.Account = nil
|
||||
b1.TargetAccount = nil
|
||||
b2.TargetAccount = nil
|
||||
|
||||
// Clear database-set fields.
|
||||
b1.CreatedAt = time.Time{}
|
||||
b2.CreatedAt = time.Time{}
|
||||
b1.UpdatedAt = time.Time{}
|
||||
b2.UpdatedAt = time.Time{}
|
||||
|
||||
return reflect.DeepEqual(b1, b2)
|
||||
}
|
||||
|
||||
var testBlocks []*gtsmodel.Block
|
||||
|
||||
for _, account1 := range suite.testAccounts {
|
||||
for _, account2 := range suite.testAccounts {
|
||||
if account1.ID == account2.ID {
|
||||
// don't block *yourself* ...
|
||||
continue
|
||||
}
|
||||
|
||||
// Create new account block.
|
||||
block := >smodel.Block{
|
||||
ID: id.NewULID(),
|
||||
URI: "http://127.0.0.1:8080/" + id.NewULID(),
|
||||
AccountID: account1.ID,
|
||||
TargetAccountID: account2.ID,
|
||||
}
|
||||
|
||||
// Attempt to place the block in database (if not already).
|
||||
if err := suite.db.PutBlock(ctx, block); err != nil {
|
||||
if err != db.ErrAlreadyExists {
|
||||
// Unrecoverable database error.
|
||||
t.Fatalf("error creating block: %v", err)
|
||||
}
|
||||
|
||||
// Fetch existing block from database between accounts.
|
||||
block, _ = suite.db.GetBlock(ctx, account1.ID, account2.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
// Append generated block to test cases.
|
||||
testBlocks = append(testBlocks, block)
|
||||
}
|
||||
}
|
||||
|
||||
for _, block := range testBlocks {
|
||||
for lookup, dbfunc := range map[string]func() (*gtsmodel.Block, error){
|
||||
"id": func() (*gtsmodel.Block, error) {
|
||||
return suite.db.GetBlockByID(ctx, block.ID)
|
||||
},
|
||||
|
||||
"uri": func() (*gtsmodel.Block, error) {
|
||||
return suite.db.GetBlockByURI(ctx, block.URI)
|
||||
},
|
||||
|
||||
"origin_target": func() (*gtsmodel.Block, error) {
|
||||
return suite.db.GetBlock(ctx, block.AccountID, block.TargetAccountID)
|
||||
},
|
||||
} {
|
||||
|
||||
// Clear database caches.
|
||||
suite.state.Caches.Init()
|
||||
|
||||
t.Logf("checking database lookup %q", lookup)
|
||||
|
||||
// Perform database function.
|
||||
checkBlock, err := dbfunc()
|
||||
if err != nil {
|
||||
if err == sentinelErr {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Errorf("error encountered for database lookup %q: %v", lookup, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check received block data.
|
||||
if !isEqual(*checkBlock, *block) {
|
||||
t.Errorf("block does not contain expected data: %+v", checkBlock)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that block origin account populated.
|
||||
if checkBlock.Account == nil || checkBlock.Account.ID != block.AccountID {
|
||||
t.Errorf("block origin account not correctly populated for: %+v", checkBlock)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that block target account populated.
|
||||
if checkBlock.TargetAccount == nil || checkBlock.TargetAccount.ID != block.TargetAccountID {
|
||||
t.Errorf("block target account not correctly populated for: %+v", checkBlock)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetFollowBy() {
|
||||
t := suite.T()
|
||||
|
||||
// Create a new context for this test.
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
// Sentinel error to mark avoiding a test case.
|
||||
sentinelErr := errors.New("sentinel")
|
||||
|
||||
// isEqual checks if 2 follow models are equal.
|
||||
isEqual := func(f1, f2 gtsmodel.Follow) bool {
|
||||
// Clear populated sub-models.
|
||||
f1.Account = nil
|
||||
f2.Account = nil
|
||||
f1.TargetAccount = nil
|
||||
f2.TargetAccount = nil
|
||||
|
||||
// Clear database-set fields.
|
||||
f1.CreatedAt = time.Time{}
|
||||
f2.CreatedAt = time.Time{}
|
||||
f1.UpdatedAt = time.Time{}
|
||||
f2.UpdatedAt = time.Time{}
|
||||
|
||||
return reflect.DeepEqual(f1, f2)
|
||||
}
|
||||
|
||||
var testFollows []*gtsmodel.Follow
|
||||
|
||||
for _, account1 := range suite.testAccounts {
|
||||
for _, account2 := range suite.testAccounts {
|
||||
if account1.ID == account2.ID {
|
||||
// don't follow *yourself* ...
|
||||
continue
|
||||
}
|
||||
|
||||
// Create new account follow.
|
||||
follow := >smodel.Follow{
|
||||
ID: id.NewULID(),
|
||||
URI: "http://127.0.0.1:8080/" + id.NewULID(),
|
||||
AccountID: account1.ID,
|
||||
TargetAccountID: account2.ID,
|
||||
}
|
||||
|
||||
// Attempt to place the follow in database (if not already).
|
||||
if err := suite.db.PutFollow(ctx, follow); err != nil {
|
||||
if err != db.ErrAlreadyExists {
|
||||
// Unrecoverable database error.
|
||||
t.Fatalf("error creating follow: %v", err)
|
||||
}
|
||||
|
||||
// Fetch existing follow from database between accounts.
|
||||
follow, _ = suite.db.GetFollow(ctx, account1.ID, account2.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
// Append generated follow to test cases.
|
||||
testFollows = append(testFollows, follow)
|
||||
}
|
||||
}
|
||||
|
||||
for _, follow := range testFollows {
|
||||
for lookup, dbfunc := range map[string]func() (*gtsmodel.Follow, error){
|
||||
"id": func() (*gtsmodel.Follow, error) {
|
||||
return suite.db.GetFollowByID(ctx, follow.ID)
|
||||
},
|
||||
|
||||
"uri": func() (*gtsmodel.Follow, error) {
|
||||
return suite.db.GetFollowByURI(ctx, follow.URI)
|
||||
},
|
||||
|
||||
"origin_target": func() (*gtsmodel.Follow, error) {
|
||||
return suite.db.GetFollow(ctx, follow.AccountID, follow.TargetAccountID)
|
||||
},
|
||||
} {
|
||||
// Clear database caches.
|
||||
suite.state.Caches.Init()
|
||||
|
||||
t.Logf("checking database lookup %q", lookup)
|
||||
|
||||
// Perform database function.
|
||||
checkFollow, err := dbfunc()
|
||||
if err != nil {
|
||||
if err == sentinelErr {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Errorf("error encountered for database lookup %q: %v", lookup, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check received follow data.
|
||||
if !isEqual(*checkFollow, *follow) {
|
||||
t.Errorf("follow does not contain expected data: %+v", checkFollow)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that follow origin account populated.
|
||||
if checkFollow.Account == nil || checkFollow.Account.ID != follow.AccountID {
|
||||
t.Errorf("follow origin account not correctly populated for: %+v", checkFollow)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that follow target account populated.
|
||||
if checkFollow.TargetAccount == nil || checkFollow.TargetAccount.ID != follow.TargetAccountID {
|
||||
t.Errorf("follow target account not correctly populated for: %+v", checkFollow)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetFollowRequestBy() {
|
||||
t := suite.T()
|
||||
|
||||
// Create a new context for this test.
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
// Sentinel error to mark avoiding a test case.
|
||||
sentinelErr := errors.New("sentinel")
|
||||
|
||||
// isEqual checks if 2 follow request models are equal.
|
||||
isEqual := func(f1, f2 gtsmodel.FollowRequest) bool {
|
||||
// Clear populated sub-models.
|
||||
f1.Account = nil
|
||||
f2.Account = nil
|
||||
f1.TargetAccount = nil
|
||||
f2.TargetAccount = nil
|
||||
|
||||
// Clear database-set fields.
|
||||
f1.CreatedAt = time.Time{}
|
||||
f2.CreatedAt = time.Time{}
|
||||
f1.UpdatedAt = time.Time{}
|
||||
f2.UpdatedAt = time.Time{}
|
||||
|
||||
return reflect.DeepEqual(f1, f2)
|
||||
}
|
||||
|
||||
var testFollowReqs []*gtsmodel.FollowRequest
|
||||
|
||||
for _, account1 := range suite.testAccounts {
|
||||
for _, account2 := range suite.testAccounts {
|
||||
if account1.ID == account2.ID {
|
||||
// don't follow *yourself* ...
|
||||
continue
|
||||
}
|
||||
|
||||
// Create new account follow request.
|
||||
followReq := >smodel.FollowRequest{
|
||||
ID: id.NewULID(),
|
||||
URI: "http://127.0.0.1:8080/" + id.NewULID(),
|
||||
AccountID: account1.ID,
|
||||
TargetAccountID: account2.ID,
|
||||
}
|
||||
|
||||
// Attempt to place the follow in database (if not already).
|
||||
if err := suite.db.PutFollowRequest(ctx, followReq); err != nil {
|
||||
if err != db.ErrAlreadyExists {
|
||||
// Unrecoverable database error.
|
||||
t.Fatalf("error creating follow request: %v", err)
|
||||
}
|
||||
|
||||
// Fetch existing follow request from database between accounts.
|
||||
followReq, _ = suite.db.GetFollowRequest(ctx, account1.ID, account2.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
// Append generated follow request to test cases.
|
||||
testFollowReqs = append(testFollowReqs, followReq)
|
||||
}
|
||||
}
|
||||
|
||||
for _, followReq := range testFollowReqs {
|
||||
for lookup, dbfunc := range map[string]func() (*gtsmodel.FollowRequest, error){
|
||||
"id": func() (*gtsmodel.FollowRequest, error) {
|
||||
return suite.db.GetFollowRequestByID(ctx, followReq.ID)
|
||||
},
|
||||
|
||||
"uri": func() (*gtsmodel.FollowRequest, error) {
|
||||
return suite.db.GetFollowRequestByURI(ctx, followReq.URI)
|
||||
},
|
||||
|
||||
"origin_target": func() (*gtsmodel.FollowRequest, error) {
|
||||
return suite.db.GetFollowRequest(ctx, followReq.AccountID, followReq.TargetAccountID)
|
||||
},
|
||||
} {
|
||||
|
||||
// Clear database caches.
|
||||
suite.state.Caches.Init()
|
||||
|
||||
t.Logf("checking database lookup %q", lookup)
|
||||
|
||||
// Perform database function.
|
||||
checkFollowReq, err := dbfunc()
|
||||
if err != nil {
|
||||
if err == sentinelErr {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Errorf("error encountered for database lookup %q: %v", lookup, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check received follow request data.
|
||||
if !isEqual(*checkFollowReq, *followReq) {
|
||||
t.Errorf("follow request does not contain expected data: %+v", checkFollowReq)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that follow request origin account populated.
|
||||
if checkFollowReq.Account == nil || checkFollowReq.Account.ID != followReq.AccountID {
|
||||
t.Errorf("follow request origin account not correctly populated for: %+v", checkFollowReq)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that follow request target account populated.
|
||||
if checkFollowReq.TargetAccount == nil || checkFollowReq.TargetAccount.ID != followReq.TargetAccountID {
|
||||
t.Errorf("follow request target account not correctly populated for: %+v", checkFollowReq)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestIsBlocked() {
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
@ -37,11 +379,11 @@ func (suite *RelationshipTestSuite) TestIsBlocked() {
|
|||
account2 := suite.testAccounts["local_account_2"].ID
|
||||
|
||||
// no blocks exist between account 1 and account 2
|
||||
blocked, err := suite.db.IsBlocked(ctx, account1, account2, false)
|
||||
blocked, err := suite.db.IsBlocked(ctx, account1, account2)
|
||||
suite.NoError(err)
|
||||
suite.False(blocked)
|
||||
|
||||
blocked, err = suite.db.IsBlocked(ctx, account2, account1, false)
|
||||
blocked, err = suite.db.IsBlocked(ctx, account2, account1)
|
||||
suite.NoError(err)
|
||||
suite.False(blocked)
|
||||
|
||||
|
|
@ -56,45 +398,24 @@ func (suite *RelationshipTestSuite) TestIsBlocked() {
|
|||
}
|
||||
|
||||
// account 1 now blocks account 2
|
||||
blocked, err = suite.db.IsBlocked(ctx, account1, account2, false)
|
||||
blocked, err = suite.db.IsBlocked(ctx, account1, account2)
|
||||
suite.NoError(err)
|
||||
suite.True(blocked)
|
||||
|
||||
// account 2 doesn't block account 1
|
||||
blocked, err = suite.db.IsBlocked(ctx, account2, account1, false)
|
||||
blocked, err = suite.db.IsBlocked(ctx, account2, account1)
|
||||
suite.NoError(err)
|
||||
suite.False(blocked)
|
||||
|
||||
// a block exists in either direction between the two
|
||||
blocked, err = suite.db.IsBlocked(ctx, account1, account2, true)
|
||||
blocked, err = suite.db.IsEitherBlocked(ctx, account1, account2)
|
||||
suite.NoError(err)
|
||||
suite.True(blocked)
|
||||
blocked, err = suite.db.IsBlocked(ctx, account2, account1, true)
|
||||
blocked, err = suite.db.IsEitherBlocked(ctx, account2, account1)
|
||||
suite.NoError(err)
|
||||
suite.True(blocked)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetBlock() {
|
||||
ctx := context.Background()
|
||||
|
||||
account1 := suite.testAccounts["local_account_1"].ID
|
||||
account2 := suite.testAccounts["local_account_2"].ID
|
||||
|
||||
if err := suite.db.PutBlock(ctx, >smodel.Block{
|
||||
ID: "01G202BCSXXJZ70BHB5KCAHH8C",
|
||||
URI: "http://localhost:8080/some_block_uri_1",
|
||||
AccountID: account1,
|
||||
TargetAccountID: account2,
|
||||
}); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
block, err := suite.db.GetBlock(ctx, account1, account2)
|
||||
suite.NoError(err)
|
||||
suite.NotNil(block)
|
||||
suite.Equal("01G202BCSXXJZ70BHB5KCAHH8C", block.ID)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestDeleteBlockByID() {
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
@ -157,7 +478,7 @@ func (suite *RelationshipTestSuite) TestDeleteBlockByURI() {
|
|||
suite.Nil(block)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestDeleteBlocksByOriginAccountID() {
|
||||
func (suite *RelationshipTestSuite) TestDeleteAccountBlocks() {
|
||||
ctx := context.Background()
|
||||
|
||||
// put a block in first
|
||||
|
|
@ -179,38 +500,7 @@ func (suite *RelationshipTestSuite) TestDeleteBlocksByOriginAccountID() {
|
|||
suite.Equal("01G202BCSXXJZ70BHB5KCAHH8C", block.ID)
|
||||
|
||||
// delete the block by originAccountID
|
||||
err = suite.db.DeleteBlocksByOriginAccountID(ctx, account1)
|
||||
suite.NoError(err)
|
||||
|
||||
// block should be gone
|
||||
block, err = suite.db.GetBlock(ctx, account1, account2)
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Nil(block)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestDeleteBlocksByTargetAccountID() {
|
||||
ctx := context.Background()
|
||||
|
||||
// put a block in first
|
||||
account1 := suite.testAccounts["local_account_1"].ID
|
||||
account2 := suite.testAccounts["local_account_2"].ID
|
||||
if err := suite.db.PutBlock(ctx, >smodel.Block{
|
||||
ID: "01G202BCSXXJZ70BHB5KCAHH8C",
|
||||
URI: "http://localhost:8080/some_block_uri_1",
|
||||
AccountID: account1,
|
||||
TargetAccountID: account2,
|
||||
}); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
// make sure the block is in the db
|
||||
block, err := suite.db.GetBlock(ctx, account1, account2)
|
||||
suite.NoError(err)
|
||||
suite.NotNil(block)
|
||||
suite.Equal("01G202BCSXXJZ70BHB5KCAHH8C", block.ID)
|
||||
|
||||
// delete the block by targetAccountID
|
||||
err = suite.db.DeleteBlocksByTargetAccountID(ctx, account2)
|
||||
err = suite.db.DeleteAccountBlocks(ctx, account1)
|
||||
suite.NoError(err)
|
||||
|
||||
// block should be gone
|
||||
|
|
@ -244,7 +534,7 @@ func (suite *RelationshipTestSuite) TestGetRelationship() {
|
|||
func (suite *RelationshipTestSuite) TestIsFollowingYes() {
|
||||
requestingAccount := suite.testAccounts["local_account_1"]
|
||||
targetAccount := suite.testAccounts["admin_account"]
|
||||
isFollowing, err := suite.db.IsFollowing(context.Background(), requestingAccount, targetAccount)
|
||||
isFollowing, err := suite.db.IsFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.True(isFollowing)
|
||||
}
|
||||
|
|
@ -252,7 +542,7 @@ func (suite *RelationshipTestSuite) TestIsFollowingYes() {
|
|||
func (suite *RelationshipTestSuite) TestIsFollowingNo() {
|
||||
requestingAccount := suite.testAccounts["admin_account"]
|
||||
targetAccount := suite.testAccounts["local_account_2"]
|
||||
isFollowing, err := suite.db.IsFollowing(context.Background(), requestingAccount, targetAccount)
|
||||
isFollowing, err := suite.db.IsFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.False(isFollowing)
|
||||
}
|
||||
|
|
@ -260,7 +550,7 @@ func (suite *RelationshipTestSuite) TestIsFollowingNo() {
|
|||
func (suite *RelationshipTestSuite) TestIsMutualFollowing() {
|
||||
requestingAccount := suite.testAccounts["local_account_1"]
|
||||
targetAccount := suite.testAccounts["admin_account"]
|
||||
isMutualFollowing, err := suite.db.IsMutualFollowing(context.Background(), requestingAccount, targetAccount)
|
||||
isMutualFollowing, err := suite.db.IsMutualFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.True(isMutualFollowing)
|
||||
}
|
||||
|
|
@ -268,7 +558,7 @@ func (suite *RelationshipTestSuite) TestIsMutualFollowing() {
|
|||
func (suite *RelationshipTestSuite) TestIsMutualFollowingNo() {
|
||||
requestingAccount := suite.testAccounts["local_account_1"]
|
||||
targetAccount := suite.testAccounts["local_account_2"]
|
||||
isMutualFollowing, err := suite.db.IsMutualFollowing(context.Background(), requestingAccount, targetAccount)
|
||||
isMutualFollowing, err := suite.db.IsMutualFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.True(isMutualFollowing)
|
||||
}
|
||||
|
|
@ -306,7 +596,7 @@ func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() {
|
|||
suite.Equal(followRequest.URI, follow.URI)
|
||||
|
||||
// Ensure notification is deleted.
|
||||
notification, err := suite.db.GetNotification(ctx, followRequestNotification.ID)
|
||||
notification, err := suite.db.GetNotificationByID(ctx, followRequestNotification.ID)
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Nil(notification)
|
||||
}
|
||||
|
|
@ -389,7 +679,7 @@ func (suite *RelationshipTestSuite) TestRejectFollowRequestOK() {
|
|||
TargetAccountID: targetAccount.ID,
|
||||
}
|
||||
|
||||
if err := suite.db.Put(ctx, followRequest); err != nil {
|
||||
if err := suite.db.PutFollowRequest(ctx, followRequest); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
|
|
@ -404,12 +694,11 @@ func (suite *RelationshipTestSuite) TestRejectFollowRequestOK() {
|
|||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
rejectedFollowRequest, err := suite.db.RejectFollowRequest(ctx, account.ID, targetAccount.ID)
|
||||
err := suite.db.RejectFollowRequest(ctx, account.ID, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.NotNil(rejectedFollowRequest)
|
||||
|
||||
// Ensure notification is deleted.
|
||||
notification, err := suite.db.GetNotification(ctx, followRequestNotification.ID)
|
||||
notification, err := suite.db.GetNotificationByID(ctx, followRequestNotification.ID)
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Nil(notification)
|
||||
}
|
||||
|
|
@ -419,9 +708,8 @@ func (suite *RelationshipTestSuite) TestRejectFollowRequestNotExisting() {
|
|||
account := suite.testAccounts["admin_account"]
|
||||
targetAccount := suite.testAccounts["local_account_2"]
|
||||
|
||||
rejectedFollowRequest, err := suite.db.RejectFollowRequest(ctx, account.ID, targetAccount.ID)
|
||||
err := suite.db.RejectFollowRequest(ctx, account.ID, targetAccount.ID)
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
suite.Nil(rejectedFollowRequest)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetAccountFollowRequests() {
|
||||
|
|
@ -440,42 +728,49 @@ func (suite *RelationshipTestSuite) TestGetAccountFollowRequests() {
|
|||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
followRequests, err := suite.db.GetFollowRequests(ctx, "", targetAccount.ID)
|
||||
followRequests, err := suite.db.GetAccountFollowRequests(ctx, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.Len(followRequests, 1)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetAccountFollows() {
|
||||
account := suite.testAccounts["local_account_1"]
|
||||
follows, err := suite.db.GetFollows(context.Background(), account.ID, "")
|
||||
follows, err := suite.db.GetAccountFollows(context.Background(), account.ID)
|
||||
suite.NoError(err)
|
||||
suite.Len(follows, 2)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestCountAccountFollows() {
|
||||
func (suite *RelationshipTestSuite) TestCountAccountFollowsLocalOnly() {
|
||||
account := suite.testAccounts["local_account_1"]
|
||||
followsCount, err := suite.db.CountFollows(context.Background(), account.ID, "")
|
||||
followsCount, err := suite.db.CountAccountLocalFollows(context.Background(), account.ID)
|
||||
suite.NoError(err)
|
||||
suite.Equal(2, followsCount)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetAccountFollowedBy() {
|
||||
func (suite *RelationshipTestSuite) TestCountAccountFollows() {
|
||||
account := suite.testAccounts["local_account_1"]
|
||||
follows, err := suite.db.GetFollows(context.Background(), "", account.ID)
|
||||
followsCount, err := suite.db.CountAccountFollows(context.Background(), account.ID)
|
||||
suite.NoError(err)
|
||||
suite.Equal(2, followsCount)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetAccountFollowers() {
|
||||
account := suite.testAccounts["local_account_1"]
|
||||
follows, err := suite.db.GetAccountFollowers(context.Background(), account.ID)
|
||||
suite.NoError(err)
|
||||
suite.Len(follows, 2)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestGetLocalFollowersIDs() {
|
||||
func (suite *RelationshipTestSuite) TestCountAccountFollowers() {
|
||||
account := suite.testAccounts["local_account_1"]
|
||||
accountIDs, err := suite.db.GetLocalFollowersIDs(context.Background(), account.ID)
|
||||
followsCount, err := suite.db.CountAccountFollowers(context.Background(), account.ID)
|
||||
suite.NoError(err)
|
||||
suite.EqualValues([]string{"01F8MH5NBDF2MV7CTC4Q5128HF", "01F8MH17FWEB39HZJ76B6VXSKF"}, accountIDs)
|
||||
suite.Equal(2, followsCount)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestCountAccountFollowedBy() {
|
||||
func (suite *RelationshipTestSuite) TestCountAccountFollowersLocalOnly() {
|
||||
account := suite.testAccounts["local_account_1"]
|
||||
followsCount, err := suite.db.CountFollows(context.Background(), "", account.ID)
|
||||
followsCount, err := suite.db.CountAccountLocalFollowers(context.Background(), account.ID)
|
||||
suite.NoError(err)
|
||||
suite.Equal(2, followsCount)
|
||||
}
|
||||
|
|
@ -484,18 +779,25 @@ func (suite *RelationshipTestSuite) TestUnfollowExisting() {
|
|||
originAccount := suite.testAccounts["local_account_1"]
|
||||
targetAccount := suite.testAccounts["admin_account"]
|
||||
|
||||
uri, err := suite.db.Unfollow(context.Background(), originAccount.ID, targetAccount.ID)
|
||||
follow, err := suite.db.GetFollow(context.Background(), originAccount.ID, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.Equal("http://localhost:8080/users/the_mighty_zork/follow/01F8PY8RHWRQZV038T4E8T9YK8", uri)
|
||||
suite.NotNil(follow)
|
||||
|
||||
err = suite.db.DeleteFollowByID(context.Background(), follow.ID)
|
||||
suite.NoError(err)
|
||||
|
||||
follow, err = suite.db.GetFollow(context.Background(), originAccount.ID, targetAccount.ID)
|
||||
suite.EqualError(err, db.ErrNoEntries.Error())
|
||||
suite.Nil(follow)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestUnfollowNotExisting() {
|
||||
originAccount := suite.testAccounts["local_account_1"]
|
||||
targetAccountID := "01GTVD9N484CZ6AM90PGGNY7GQ"
|
||||
|
||||
uri, err := suite.db.Unfollow(context.Background(), originAccount.ID, targetAccountID)
|
||||
suite.NoError(err)
|
||||
suite.Empty(uri)
|
||||
follow, err := suite.db.GetFollow(context.Background(), originAccount.ID, targetAccountID)
|
||||
suite.EqualError(err, db.ErrNoEntries.Error())
|
||||
suite.Nil(follow)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestUnfollowRequestExisting() {
|
||||
|
|
@ -510,22 +812,29 @@ func (suite *RelationshipTestSuite) TestUnfollowRequestExisting() {
|
|||
TargetAccountID: targetAccount.ID,
|
||||
}
|
||||
|
||||
if err := suite.db.Put(ctx, followRequest); err != nil {
|
||||
if err := suite.db.PutFollowRequest(ctx, followRequest); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
uri, err := suite.db.UnfollowRequest(context.Background(), originAccount.ID, targetAccount.ID)
|
||||
followRequest, err := suite.db.GetFollowRequest(context.Background(), originAccount.ID, targetAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.Equal("http://localhost:8080/weeeeeeeeeeeeeeeee", uri)
|
||||
suite.NotNil(followRequest)
|
||||
|
||||
err = suite.db.DeleteFollowRequestByID(context.Background(), followRequest.ID)
|
||||
suite.NoError(err)
|
||||
|
||||
followRequest, err = suite.db.GetFollowRequest(context.Background(), originAccount.ID, targetAccount.ID)
|
||||
suite.EqualError(err, db.ErrNoEntries.Error())
|
||||
suite.Nil(followRequest)
|
||||
}
|
||||
|
||||
func (suite *RelationshipTestSuite) TestUnfollowRequestNotExisting() {
|
||||
originAccount := suite.testAccounts["local_account_1"]
|
||||
targetAccountID := "01GTVD9N484CZ6AM90PGGNY7GQ"
|
||||
|
||||
uri, err := suite.db.UnfollowRequest(context.Background(), originAccount.ID, targetAccountID)
|
||||
suite.NoError(err)
|
||||
suite.Empty(uri)
|
||||
followRequest, err := suite.db.GetFollowRequest(context.Background(), originAccount.ID, targetAccountID)
|
||||
suite.EqualError(err, db.ErrNoEntries.Error())
|
||||
suite.Nil(followRequest)
|
||||
}
|
||||
|
||||
func TestRelationshipTestSuite(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue