diff options
author | 2022-09-02 10:58:42 +0100 | |
---|---|---|
committer | 2022-09-02 11:58:42 +0200 | |
commit | 077e66381fffb47038a99ce82c7c07a1f1b19f62 (patch) | |
tree | 69680266fae036a7da476ead8d45a37ebdb7d9c5 /internal/cache/account_test.go | |
parent | [performance] use GetAccountByUsernameDomain() for local account lookups to r... (diff) | |
download | gotosocial-077e66381fffb47038a99ce82c7c07a1f1b19f62.tar.xz |
[performance] cache account db lookups by public key URI (#795)
Signed-off-by: kim <grufwub@gmail.com>
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/cache/account_test.go')
-rw-r--r-- | internal/cache/account_test.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/internal/cache/account_test.go b/internal/cache/account_test.go index a6d3c6b7d..d373e5f1d 100644 --- a/internal/cache/account_test.go +++ b/internal/cache/account_test.go @@ -19,6 +19,7 @@ package cache_test import ( + "fmt" "testing" "github.com/stretchr/testify/suite" @@ -59,19 +60,23 @@ func (suite *AccountCacheTestSuite) TestAccountCache() { // Check we can retrieve check, ok = suite.cache.GetByID(account.ID) if !ok && !accountIs(account, check) { - suite.Fail("Failed to fetch expected account with ID: %s", account.ID) + suite.Fail(fmt.Sprintf("Failed to fetch expected account with ID: %s", account.ID)) } check, ok = suite.cache.GetByURI(account.URI) if account.URI != "" && !ok && !accountIs(account, check) { - suite.Fail("Failed to fetch expected account with URI: %s", account.URI) + suite.Fail(fmt.Sprintf("Failed to fetch expected account with URI: %s", account.URI)) } check, ok = suite.cache.GetByURL(account.URL) if account.URL != "" && !ok && !accountIs(account, check) { - suite.Fail("Failed to fetch expected account with URL: %s", account.URL) + suite.Fail(fmt.Sprintf("Failed to fetch expected account with URL: %s", account.URL)) + } + check, ok = suite.cache.GetByPubkeyID(account.PublicKeyURI) + if account.PublicKeyURI != "" && !ok && !accountIs(account, check) { + suite.Fail(fmt.Sprintf("Failed to fetch expected account with public key URI: %s", account.PublicKeyURI)) } check, ok = suite.cache.GetByUsernameDomain(account.Username, account.Domain) if !ok && !accountIs(account, check) { - suite.Fail("Failed to fetch expected account with username/domain: %s/%s", account.Username, account.Domain) + suite.Fail(fmt.Sprintf("Failed to fetch expected account with username/domain: %s/%s", account.Username, account.Domain)) } } } @@ -81,5 +86,11 @@ func TestAccountCache(t *testing.T) { } func accountIs(account1, account2 *gtsmodel.Account) bool { - return account1.ID == account2.ID && account1.URI == account2.URI && account1.URL == account2.URL + if account1 == nil || account2 == nil { + return account1 == account2 + } + return account1.ID == account2.ID && + account1.URI == account2.URI && + account1.URL == account2.URL && + account1.PublicKeyURI == account2.PublicKeyURI } |