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.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.go')
-rw-r--r-- | internal/cache/account.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/cache/account.go b/internal/cache/account.go index 1f958ebb8..5ba97c7d8 100644 --- a/internal/cache/account.go +++ b/internal/cache/account.go @@ -37,6 +37,7 @@ func NewAccountCache() *AccountCache { RegisterLookups: func(lm *cache.LookupMap[string, string]) { lm.RegisterLookup("uri") lm.RegisterLookup("url") + lm.RegisterLookup("pubkeyid") lm.RegisterLookup("usernamedomain") }, @@ -47,6 +48,7 @@ func NewAccountCache() *AccountCache { if url := acc.URL; url != "" { lm.Set("url", url, acc.ID) } + lm.Set("pubkeyid", acc.PublicKeyURI, acc.ID) lm.Set("usernamedomain", usernameDomainKey(acc.Username, acc.Domain), acc.ID) }, @@ -57,6 +59,7 @@ func NewAccountCache() *AccountCache { if url := acc.URL; url != "" { lm.Delete("url", url) } + lm.Delete("pubkeyid", acc.PublicKeyURI) lm.Delete("usernamedomain", usernameDomainKey(acc.Username, acc.Domain)) }, }) @@ -80,10 +83,16 @@ func (c *AccountCache) GetByURI(uri string) (*gtsmodel.Account, bool) { return c.cache.GetBy("uri", uri) } +// GettByUsernameDomain attempts to fetch an account from the cache by its username@domain combo (or just username), you will receive a copy for thread-safety. func (c *AccountCache) GetByUsernameDomain(username string, domain string) (*gtsmodel.Account, bool) { return c.cache.GetBy("usernamedomain", usernameDomainKey(username, domain)) } +// GetByPubkeyID attempts to fetch an account from the cache by its public key URI (ID), you will receive a copy for thread-safety. +func (c *AccountCache) GetByPubkeyID(id string) (*gtsmodel.Account, bool) { + return c.cache.GetBy("pubkeyid", id) +} + // Put places a account in the cache, ensuring that the object place is a copy for thread-safety func (c *AccountCache) Put(account *gtsmodel.Account) { if account == nil || account.ID == "" { |