diff options
author | 2022-05-02 12:53:46 +0200 | |
---|---|---|
committer | 2022-05-02 11:53:46 +0100 | |
commit | a5852fd7e43bf97ea7def9de20cd6d02d954094d (patch) | |
tree | d72b7fe9bf603786a5533e6b566a8412b2b8f634 /internal/db/bundb/relationship_test.go | |
parent | Add logging to the new generic worker package (#516) (diff) | |
download | gotosocial-a5852fd7e43bf97ea7def9de20cd6d02d954094d.tar.xz |
[performance] Speed up some of the slower db queries (#523)
* remove unnecessary LOWER() db calls
* warn during slow db queries
* use bundb built-in exists function
* add db block test
* update account block query
* add domain block db test
* optimize domain block query
* fix implementing wrong test
* exclude most columns when checking block
* go fmt
* remote more unnecessary use of LOWER()
Diffstat (limited to 'internal/db/bundb/relationship_test.go')
-rw-r--r-- | internal/db/bundb/relationship_test.go | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/internal/db/bundb/relationship_test.go b/internal/db/bundb/relationship_test.go index bb0f0e3da..34fe85a57 100644 --- a/internal/db/bundb/relationship_test.go +++ b/internal/db/bundb/relationship_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/db" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) type RelationshipTestSuite struct { @@ -32,7 +33,45 @@ type RelationshipTestSuite struct { } func (suite *RelationshipTestSuite) TestIsBlocked() { - suite.Suite.T().Skip("TODO: implement") + 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 + blocked, err := suite.db.IsBlocked(ctx, account1, account2, false) + suite.NoError(err) + suite.False(blocked) + + blocked, err = suite.db.IsBlocked(ctx, account2, account1, false) + suite.NoError(err) + suite.False(blocked) + + // have account1 block account2 + suite.db.Put(ctx, >smodel.Block{ + ID: "01G202BCSXXJZ70BHB5KCAHH8C", + URI: "http://localhost:8080/some_block_uri_1", + AccountID: account1, + TargetAccountID: account2, + }) + + // account 1 now blocks account 2 + blocked, err = suite.db.IsBlocked(ctx, account1, account2, false) + suite.NoError(err) + suite.True(blocked) + + // account 2 doesn't block account 1 + blocked, err = suite.db.IsBlocked(ctx, account2, account1, false) + suite.NoError(err) + suite.False(blocked) + + // a block exists in either direction between the two + blocked, err = suite.db.IsBlocked(ctx, account1, account2, true) + suite.NoError(err) + suite.True(blocked) + blocked, err = suite.db.IsBlocked(ctx, account2, account1, true) + suite.NoError(err) + suite.True(blocked) } func (suite *RelationshipTestSuite) TestGetBlock() { |