[performance] cache account db lookups by public key URI (#795)

Signed-off-by: kim <grufwub@gmail.com>

Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2022-09-02 10:58:42 +01:00 committed by GitHub
commit 077e66381f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 19 deletions

View file

@ -106,6 +106,18 @@ func (a *accountDB) GetAccountByUsernameDomain(ctx context.Context, username str
)
}
func (a *accountDB) GetAccountByPubkeyID(ctx context.Context, id string) (*gtsmodel.Account, db.Error) {
return a.getAccount(
ctx,
func() (*gtsmodel.Account, bool) {
return a.cache.GetByPubkeyID(id)
},
func(account *gtsmodel.Account) error {
return a.newAccountQ(account).Where("account.public_key_uri = ?", id).Scan(ctx)
},
)
}
func (a *accountDB) getAccount(ctx context.Context, cacheGet func() (*gtsmodel.Account, bool), dbQuery func(*gtsmodel.Account) error) (*gtsmodel.Account, db.Error) {
// Attempt to fetch cached account
account, cached := cacheGet()