diff options
author | 2022-10-03 10:46:11 +0200 | |
---|---|---|
committer | 2022-10-03 10:46:11 +0200 | |
commit | 56f53a2a6f85876485e2ae67d48b78b448caed6e (patch) | |
tree | 9bd8d3fcaffd515d3dc90ff22c6cee17e8d0b073 /internal/api/security/tokencheck.go | |
parent | [feature] Enlarge active/hovered custom emojis in statuses (#877) (diff) | |
download | gotosocial-56f53a2a6f85876485e2ae67d48b78b448caed6e.tar.xz |
[performance] add user cache and database (#879)
* go fmt
* add + use user cache and database
* fix import
* update tests
* remove unused relation
Diffstat (limited to 'internal/api/security/tokencheck.go')
-rw-r--r-- | internal/api/security/tokencheck.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/internal/api/security/tokencheck.go b/internal/api/security/tokencheck.go index 3df7ee943..9f2b7f36e 100644 --- a/internal/api/security/tokencheck.go +++ b/internal/api/security/tokencheck.go @@ -52,8 +52,8 @@ func (m *Module) TokenCheck(c *gin.Context) { log.Tracef("authenticated user %s with bearer token, scope is %s", userID, ti.GetScope()) // fetch user for this token - user := >smodel.User{} - if err := m.db.GetByID(ctx, userID, user); err != nil { + user, err := m.db.GetUserByID(ctx, userID) + if err != nil { if err != db.ErrNoEntries { log.Errorf("database error looking for user with id %s: %s", userID, err) return @@ -80,22 +80,25 @@ func (m *Module) TokenCheck(c *gin.Context) { c.Set(oauth.SessionAuthorizedUser, user) // fetch account for this token - acct, err := m.db.GetAccountByID(ctx, user.AccountID) - if err != nil { - if err != db.ErrNoEntries { - log.Errorf("database error looking for account with id %s: %s", user.AccountID, err) + if user.Account == nil { + acct, err := m.db.GetAccountByID(ctx, user.AccountID) + if err != nil { + if err != db.ErrNoEntries { + log.Errorf("database error looking for account with id %s: %s", user.AccountID, err) + return + } + log.Warnf("no account found for userID %s", userID) return } - log.Warnf("no account found for userID %s", userID) - return + user.Account = acct } - if !acct.SuspendedAt.IsZero() { + if !user.Account.SuspendedAt.IsZero() { log.Warnf("authenticated user %s's account (accountId=%s) has been suspended", userID, user.AccountID) return } - c.Set(oauth.SessionAuthorizedAccount, acct) + c.Set(oauth.SessionAuthorizedAccount, user.Account) } // check for application token |