2023-03-12 16:00:57 +01:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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/>.
|
2021-09-01 11:08:21 +02:00
|
|
|
|
|
|
|
package bundb_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
"errors"
|
|
|
|
"reflect"
|
2021-09-01 11:08:21 +02:00
|
|
|
"testing"
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
"time"
|
2021-09-01 11:08:21 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2022-05-02 12:53:46 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
2023-08-07 19:38:11 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
2021-09-01 11:08:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type RelationshipTestSuite struct {
|
|
|
|
BunDBStandardTestSuite
|
|
|
|
}
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-01 11:08:21 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestIsBlocked() {
|
2022-05-02 12:53:46 +02:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
account1 := suite.testAccounts["local_account_1"].ID
|
|
|
|
account2 := suite.testAccounts["local_account_2"].ID
|
|
|
|
|
|
|
|
// no blocks exist between account 1 and account 2
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
blocked, err := suite.db.IsBlocked(ctx, account1, account2)
|
2022-05-02 12:53:46 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.False(blocked)
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
blocked, err = suite.db.IsBlocked(ctx, account2, account1)
|
2022-05-02 12:53:46 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.False(blocked)
|
|
|
|
|
|
|
|
// have account1 block account2
|
2022-11-20 17:33:49 +01:00
|
|
|
if err := suite.db.PutBlock(ctx, >smodel.Block{
|
2022-05-02 12:53:46 +02:00
|
|
|
ID: "01G202BCSXXJZ70BHB5KCAHH8C",
|
|
|
|
URI: "http://localhost:8080/some_block_uri_1",
|
|
|
|
AccountID: account1,
|
|
|
|
TargetAccountID: account2,
|
2022-10-08 13:50:48 +02:00
|
|
|
}); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
2022-05-02 12:53:46 +02:00
|
|
|
|
|
|
|
// account 1 now blocks account 2
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
blocked, err = suite.db.IsBlocked(ctx, account1, account2)
|
2022-05-02 12:53:46 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.True(blocked)
|
|
|
|
|
|
|
|
// account 2 doesn't block account 1
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
blocked, err = suite.db.IsBlocked(ctx, account2, account1)
|
2022-05-02 12:53:46 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.False(blocked)
|
|
|
|
|
|
|
|
// a block exists in either direction between the two
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
blocked, err = suite.db.IsEitherBlocked(ctx, account1, account2)
|
2022-05-02 12:53:46 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.True(blocked)
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
blocked, err = suite.db.IsEitherBlocked(ctx, account2, account1)
|
2022-05-02 12:53:46 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.True(blocked)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-11-20 17:33:49 +01:00
|
|
|
func (suite *RelationshipTestSuite) TestDeleteBlockByID() {
|
|
|
|
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 ID
|
|
|
|
err = suite.db.DeleteBlockByID(ctx, "01G202BCSXXJZ70BHB5KCAHH8C")
|
|
|
|
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) TestDeleteBlockByURI() {
|
|
|
|
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 uri
|
|
|
|
err = suite.db.DeleteBlockByURI(ctx, "http://localhost:8080/some_block_uri_1")
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// block should be gone
|
|
|
|
block, err = suite.db.GetBlock(ctx, account1, account2)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Nil(block)
|
|
|
|
}
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestDeleteAccountBlocks() {
|
2022-11-20 17:33:49 +01:00
|
|
|
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 originAccountID
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
err = suite.db.DeleteAccountBlocks(ctx, account1)
|
2022-11-20 17:33:49 +01:00
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// block should be gone
|
|
|
|
block, err = suite.db.GetBlock(ctx, account1, account2)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Nil(block)
|
|
|
|
}
|
|
|
|
|
2024-06-06 18:38:02 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestDeleteAccountMutes() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Add a mute.
|
|
|
|
accountID1 := suite.testAccounts["local_account_1"].ID
|
|
|
|
accountID2 := suite.testAccounts["local_account_2"].ID
|
|
|
|
muteID := "01HZGZ3F3C7S1TTPE8F9VPZDCB"
|
|
|
|
err := suite.db.PutMute(ctx, >smodel.UserMute{
|
|
|
|
ID: muteID,
|
|
|
|
AccountID: accountID1,
|
|
|
|
TargetAccountID: accountID2,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the mute is in the DB.
|
|
|
|
mute, err := suite.db.GetMute(ctx, accountID1, accountID2)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
if suite.NotNil(mute) {
|
|
|
|
suite.Equal(muteID, mute.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete all mutes owned by that account.
|
|
|
|
err = suite.db.DeleteAccountMutes(ctx, accountID1)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mute should be gone.
|
|
|
|
mute, err = suite.db.GetMute(ctx, accountID1, accountID2)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Nil(mute)
|
|
|
|
}
|
|
|
|
|
2021-09-01 11:08:21 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestGetRelationship() {
|
2022-10-08 13:50:48 +02:00
|
|
|
requestingAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccount := suite.testAccounts["admin_account"]
|
|
|
|
|
|
|
|
relationship, err := suite.db.GetRelationship(context.Background(), requestingAccount.ID, targetAccount.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(relationship)
|
|
|
|
|
|
|
|
suite.True(relationship.Following)
|
|
|
|
suite.True(relationship.ShowingReblogs)
|
|
|
|
suite.False(relationship.Notifying)
|
|
|
|
suite.True(relationship.FollowedBy)
|
|
|
|
suite.False(relationship.Blocking)
|
|
|
|
suite.False(relationship.BlockedBy)
|
|
|
|
suite.False(relationship.Muting)
|
|
|
|
suite.False(relationship.MutingNotifications)
|
|
|
|
suite.False(relationship.Requested)
|
|
|
|
suite.False(relationship.DomainBlocking)
|
|
|
|
suite.False(relationship.Endorsed)
|
|
|
|
suite.Empty(relationship.Note)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *RelationshipTestSuite) TestIsFollowingYes() {
|
|
|
|
requestingAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccount := suite.testAccounts["admin_account"]
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
isFollowing, err := suite.db.IsFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.True(isFollowing)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestIsFollowingNo() {
|
|
|
|
requestingAccount := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
isFollowing, err := suite.db.IsFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.False(isFollowing)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *RelationshipTestSuite) TestIsMutualFollowing() {
|
2022-10-08 13:50:48 +02:00
|
|
|
requestingAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccount := suite.testAccounts["admin_account"]
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
isMutualFollowing, err := suite.db.IsMutualFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.True(isMutualFollowing)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *RelationshipTestSuite) TestIsMutualFollowingNo() {
|
|
|
|
requestingAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
isMutualFollowing, err := suite.db.IsMutualFollowing(context.Background(), requestingAccount.ID, targetAccount.ID)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.True(isMutualFollowing)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() {
|
|
|
|
ctx := context.Background()
|
|
|
|
account := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
|
|
|
|
2023-03-31 12:16:25 +02:00
|
|
|
// Fetch relationship before follow request.
|
|
|
|
relationship, err := suite.db.GetRelationship(ctx, account.ID, targetAccount.ID)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.False(relationship.Following)
|
|
|
|
suite.False(relationship.Requested)
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
followRequest := >smodel.FollowRequest{
|
|
|
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
|
|
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
|
|
|
AccountID: account.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
2022-10-08 13:50:48 +02:00
|
|
|
|
2023-03-31 12:16:25 +02:00
|
|
|
if err := suite.db.PutFollowRequest(ctx, followRequest); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch relationship while follow requested.
|
|
|
|
relationship, err = suite.db.GetRelationship(ctx, account.ID, targetAccount.ID)
|
|
|
|
if err != nil {
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
2023-03-31 12:16:25 +02:00
|
|
|
suite.False(relationship.Following)
|
|
|
|
suite.True(relationship.Requested)
|
2022-10-08 13:50:48 +02:00
|
|
|
|
2024-02-20 18:50:54 +01:00
|
|
|
// Check the other way around too; local_account_2
|
|
|
|
// should have requested_by true for admin now.
|
|
|
|
inverse, err := suite.db.GetRelationship(ctx, targetAccount.ID, account.ID)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.True(inverse.RequestedBy)
|
|
|
|
|
2023-03-20 19:10:08 +01:00
|
|
|
followRequestNotification := >smodel.Notification{
|
|
|
|
ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB",
|
|
|
|
OriginAccountID: account.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
NotificationType: gtsmodel.NotificationFollowRequest,
|
|
|
|
}
|
|
|
|
|
2023-03-31 12:16:25 +02:00
|
|
|
if err := suite.db.PutNotification(ctx, followRequestNotification); err != nil {
|
2023-03-20 19:10:08 +01:00
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
follow, err := suite.db.AcceptFollowRequest(ctx, account.ID, targetAccount.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(follow)
|
|
|
|
suite.Equal(followRequest.URI, follow.URI)
|
|
|
|
|
|
|
|
// Ensure notification is deleted.
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
notification, err := suite.db.GetNotificationByID(ctx, followRequestNotification.ID)
|
2023-03-20 19:10:08 +01:00
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Nil(notification)
|
2023-03-31 12:16:25 +02:00
|
|
|
|
|
|
|
// Fetch relationship while followed.
|
|
|
|
relationship, err = suite.db.GetRelationship(ctx, account.ID, targetAccount.ID)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
suite.True(relationship.Following)
|
|
|
|
suite.False(relationship.Requested)
|
2023-03-20 19:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *RelationshipTestSuite) TestAcceptFollowRequestNoNotification() {
|
|
|
|
ctx := context.Background()
|
|
|
|
account := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
|
|
|
|
|
|
|
followRequest := >smodel.FollowRequest{
|
|
|
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
|
|
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
|
|
|
AccountID: account.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := suite.db.Put(ctx, followRequest); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlike the above test, don't create a notification.
|
|
|
|
// Follow request accept should still produce no error.
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
follow, err := suite.db.AcceptFollowRequest(ctx, account.ID, targetAccount.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(follow)
|
|
|
|
suite.Equal(followRequest.URI, follow.URI)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestAcceptFollowRequestNotExisting() {
|
|
|
|
ctx := context.Background()
|
|
|
|
account := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
|
|
|
|
|
|
|
follow, err := suite.db.AcceptFollowRequest(ctx, account.ID, targetAccount.ID)
|
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Nil(follow)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestAcceptFollowRequestFollowAlreadyExists() {
|
|
|
|
ctx := context.Background()
|
|
|
|
account := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccount := suite.testAccounts["admin_account"]
|
|
|
|
|
|
|
|
// follow already exists in the db from local_account_1 -> admin_account
|
|
|
|
existingFollow := >smodel.Follow{}
|
|
|
|
if err := suite.db.GetByID(ctx, suite.testFollows["local_account_1_admin_account"].ID, existingFollow); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
followRequest := >smodel.FollowRequest{
|
|
|
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
|
|
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
|
|
|
AccountID: account.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := suite.db.Put(ctx, followRequest); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
follow, err := suite.db.AcceptFollowRequest(ctx, account.ID, targetAccount.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(follow)
|
|
|
|
|
|
|
|
// uri should be equal to value of new/overlapping follow request
|
|
|
|
suite.NotEqual(followRequest.URI, existingFollow.URI)
|
|
|
|
suite.Equal(followRequest.URI, follow.URI)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestRejectFollowRequestOK() {
|
|
|
|
ctx := context.Background()
|
|
|
|
account := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
|
|
|
|
|
|
|
followRequest := >smodel.FollowRequest{
|
|
|
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
|
|
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
|
|
|
AccountID: account.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
}
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
if err := suite.db.PutFollowRequest(ctx, followRequest); err != nil {
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
2023-03-20 19:10:08 +01:00
|
|
|
followRequestNotification := >smodel.Notification{
|
|
|
|
ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB",
|
|
|
|
OriginAccountID: account.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
NotificationType: gtsmodel.NotificationFollowRequest,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := suite.db.Put(ctx, followRequestNotification); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
err := suite.db.RejectFollowRequest(ctx, account.ID, targetAccount.ID)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
2023-03-20 19:10:08 +01:00
|
|
|
|
|
|
|
// Ensure notification is deleted.
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
notification, err := suite.db.GetNotificationByID(ctx, followRequestNotification.ID)
|
2023-03-20 19:10:08 +01:00
|
|
|
suite.ErrorIs(err, db.ErrNoEntries)
|
|
|
|
suite.Nil(notification)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestRejectFollowRequestNotExisting() {
|
|
|
|
ctx := context.Background()
|
|
|
|
account := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
2021-09-01 11:08:21 +02: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>
2023-03-28 15:03:14 +02:00
|
|
|
err := suite.db.RejectFollowRequest(ctx, account.ID, targetAccount.ID)
|
2023-07-08 16:43:12 +02:00
|
|
|
suite.NoError(err)
|
2022-10-08 13:50:48 +02:00
|
|
|
}
|
2021-09-01 11:08:21 +02:00
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestGetAccountFollowRequests() {
|
|
|
|
ctx := context.Background()
|
|
|
|
account := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
2021-09-01 11:08:21 +02:00
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
followRequest := >smodel.FollowRequest{
|
|
|
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
|
|
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
|
|
|
AccountID: account.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
2022-10-08 13:50:48 +02:00
|
|
|
|
|
|
|
if err := suite.db.Put(ctx, followRequest); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:00:35 +02:00
|
|
|
followRequests, err := suite.db.GetAccountFollowRequests(ctx, targetAccount.ID, nil)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.Len(followRequests, 1)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:50:48 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestGetAccountFollows() {
|
|
|
|
account := suite.testAccounts["local_account_1"]
|
2023-09-12 15:00:35 +02:00
|
|
|
follows, err := suite.db.GetAccountFollows(context.Background(), account.ID, nil)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.Len(follows, 2)
|
|
|
|
}
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestGetAccountFollowers() {
|
2022-10-08 13:50:48 +02:00
|
|
|
account := suite.testAccounts["local_account_1"]
|
2023-09-12 15:00:35 +02:00
|
|
|
follows, err := suite.db.GetAccountFollowers(context.Background(), account.ID, nil)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.Len(follows, 2)
|
|
|
|
}
|
|
|
|
|
2023-03-20 19:10:08 +01:00
|
|
|
func (suite *RelationshipTestSuite) TestUnfollowExisting() {
|
|
|
|
originAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccount := suite.testAccounts["admin_account"]
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
follow, err := suite.db.GetFollow(context.Background(), originAccount.ID, targetAccount.ID)
|
2022-10-08 13:50:48 +02:00
|
|
|
suite.NoError(err)
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
suite.NotNil(follow)
|
2023-05-25 10:37:38 +02:00
|
|
|
followID := follow.ID
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
|
2024-09-16 18:46:09 +02:00
|
|
|
// We should have lists that this follow is a part of.
|
|
|
|
lists, err := suite.db.GetListsContainingFollowID(context.Background(), followID)
|
2023-05-25 10:37:38 +02:00
|
|
|
suite.NoError(err)
|
2024-09-16 18:46:09 +02:00
|
|
|
suite.NotEmpty(lists)
|
2023-05-25 10:37:38 +02:00
|
|
|
|
|
|
|
err = suite.db.DeleteFollowByID(context.Background(), followID)
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
follow, err = suite.db.GetFollow(context.Background(), originAccount.ID, targetAccount.ID)
|
|
|
|
suite.EqualError(err, db.ErrNoEntries.Error())
|
|
|
|
suite.Nil(follow)
|
2023-05-25 10:37:38 +02:00
|
|
|
|
2024-09-16 18:46:09 +02:00
|
|
|
// Lists containing this follow should return empty too.
|
|
|
|
lists, err = suite.db.GetListsContainingFollowID(context.Background(), followID)
|
2023-05-25 10:37:38 +02:00
|
|
|
suite.NoError(err)
|
2024-09-16 18:46:09 +02:00
|
|
|
suite.Empty(lists)
|
2023-03-20 19:10:08 +01:00
|
|
|
}
|
|
|
|
|
2023-05-25 10:37:38 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestGetFollowNotExisting() {
|
2023-03-20 19:10:08 +01:00
|
|
|
originAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccountID := "01GTVD9N484CZ6AM90PGGNY7GQ"
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
follow, err := suite.db.GetFollow(context.Background(), originAccount.ID, targetAccountID)
|
|
|
|
suite.EqualError(err, db.ErrNoEntries.Error())
|
|
|
|
suite.Nil(follow)
|
2023-03-20 19:10:08 +01:00
|
|
|
}
|
|
|
|
|
2023-07-08 16:43:12 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestDeleteFollow() {
|
|
|
|
ctx := context.Background()
|
|
|
|
originAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccount := suite.testAccounts["admin_account"]
|
|
|
|
|
|
|
|
err := suite.db.DeleteFollow(ctx, originAccount.ID, targetAccount.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
follow, err := suite.db.GetFollow(ctx, originAccount.ID, targetAccount.ID)
|
|
|
|
suite.EqualError(err, db.ErrNoEntries.Error())
|
|
|
|
suite.Nil(follow)
|
|
|
|
}
|
|
|
|
|
2023-03-20 19:10:08 +01:00
|
|
|
func (suite *RelationshipTestSuite) TestUnfollowRequestExisting() {
|
|
|
|
ctx := context.Background()
|
|
|
|
originAccount := suite.testAccounts["admin_account"]
|
|
|
|
targetAccount := suite.testAccounts["local_account_2"]
|
|
|
|
|
|
|
|
followRequest := >smodel.FollowRequest{
|
|
|
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
|
|
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
|
|
|
AccountID: originAccount.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
}
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
if err := suite.db.PutFollowRequest(ctx, followRequest); err != nil {
|
2023-03-20 19:10:08 +01:00
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
followRequest, err := suite.db.GetFollowRequest(context.Background(), originAccount.ID, targetAccount.ID)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(followRequest)
|
|
|
|
|
|
|
|
err = suite.db.DeleteFollowRequestByID(context.Background(), followRequest.ID)
|
2023-03-20 19:10:08 +01:00
|
|
|
suite.NoError(err)
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
|
|
|
|
followRequest, err = suite.db.GetFollowRequest(context.Background(), originAccount.ID, targetAccount.ID)
|
|
|
|
suite.EqualError(err, db.ErrNoEntries.Error())
|
|
|
|
suite.Nil(followRequest)
|
2023-03-20 19:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *RelationshipTestSuite) TestUnfollowRequestNotExisting() {
|
|
|
|
originAccount := suite.testAccounts["local_account_1"]
|
|
|
|
targetAccountID := "01GTVD9N484CZ6AM90PGGNY7GQ"
|
|
|
|
|
[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>
2023-03-28 15:03:14 +02:00
|
|
|
followRequest, err := suite.db.GetFollowRequest(context.Background(), originAccount.ID, targetAccountID)
|
|
|
|
suite.EqualError(err, db.ErrNoEntries.Error())
|
|
|
|
suite.Nil(followRequest)
|
2021-09-01 11:08:21 +02:00
|
|
|
}
|
|
|
|
|
2023-04-10 21:56:02 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestUpdateFollow() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
follow := >smodel.Follow{}
|
|
|
|
*follow = *suite.testFollows["local_account_1_admin_account"]
|
|
|
|
|
2023-08-07 19:38:11 +02:00
|
|
|
follow.Notify = util.Ptr(true)
|
2023-04-10 21:56:02 +02:00
|
|
|
if err := suite.db.UpdateFollow(ctx, follow, "notify"); err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
dbFollow, err := suite.db.GetFollowByID(ctx, follow.ID)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
suite.True(*dbFollow.Notify)
|
|
|
|
|
|
|
|
relationship, err := suite.db.GetRelationship(ctx, follow.AccountID, follow.TargetAccountID)
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
suite.True(relationship.Notifying)
|
|
|
|
}
|
|
|
|
|
2023-07-27 10:30:39 +02:00
|
|
|
func (suite *RelationshipTestSuite) TestGetNote() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Retrieve a fixture note
|
|
|
|
account1 := suite.testAccounts["local_account_1"].ID
|
|
|
|
account2 := suite.testAccounts["local_account_2"].ID
|
|
|
|
expectedNote := suite.testAccountNotes["local_account_2_note_on_1"]
|
|
|
|
note, err := suite.db.GetNote(ctx, account2, account1)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(note)
|
|
|
|
suite.Equal(expectedNote.ID, note.ID)
|
|
|
|
suite.Equal(expectedNote.Comment, note.Comment)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *RelationshipTestSuite) TestPutNote() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// put a note in
|
|
|
|
account1 := suite.testAccounts["local_account_1"].ID
|
|
|
|
account2 := suite.testAccounts["local_account_2"].ID
|
|
|
|
err := suite.db.PutNote(ctx, >smodel.AccountNote{
|
|
|
|
ID: "01H539R2NA0M83JX15Y5RWKE97",
|
|
|
|
AccountID: account1,
|
|
|
|
TargetAccountID: account2,
|
|
|
|
Comment: "foo",
|
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// make sure the note is in the db
|
|
|
|
note, err := suite.db.GetNote(ctx, account1, account2)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(note)
|
|
|
|
suite.Equal("01H539R2NA0M83JX15Y5RWKE97", note.ID)
|
|
|
|
suite.Equal("foo", note.Comment)
|
|
|
|
|
|
|
|
// update the note
|
|
|
|
note.Comment = "bar"
|
|
|
|
err = suite.db.PutNote(ctx, note)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// make sure the comment changes
|
|
|
|
note, err = suite.db.GetNote(ctx, account1, account2)
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.NotNil(note)
|
|
|
|
suite.Equal("bar", note.Comment)
|
|
|
|
}
|
|
|
|
|
2021-09-01 11:08:21 +02:00
|
|
|
func TestRelationshipTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(RelationshipTestSuite))
|
|
|
|
}
|