mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
User: Optimize signed in user cache management (#59090)
* only access the cache if a user ID is set * ignore all negative values
This commit is contained in:
parent
c02f2321c1
commit
d7a652ff7f
@ -232,11 +232,15 @@ func (s *Service) SetUsingOrg(ctx context.Context, cmd *user.SetUsingOrgCommand)
|
||||
|
||||
func (s *Service) GetSignedInUserWithCacheCtx(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
||||
var signedInUser *user.SignedInUser
|
||||
cacheKey := newSignedInUserCacheKey(query.OrgID, query.UserID)
|
||||
if cached, found := s.cacheService.Get(cacheKey); found {
|
||||
cachedUser := cached.(user.SignedInUser)
|
||||
signedInUser = &cachedUser
|
||||
return signedInUser, nil
|
||||
|
||||
// only check cache if we have a user ID and an org ID in query
|
||||
if query.OrgID > 0 && query.UserID > 0 {
|
||||
cacheKey := newSignedInUserCacheKey(query.OrgID, query.UserID)
|
||||
if cached, found := s.cacheService.Get(cacheKey); found {
|
||||
cachedUser := cached.(user.SignedInUser)
|
||||
signedInUser = &cachedUser
|
||||
return signedInUser, nil
|
||||
}
|
||||
}
|
||||
|
||||
result, err := s.GetSignedInUser(ctx, query)
|
||||
@ -244,7 +248,7 @@ func (s *Service) GetSignedInUserWithCacheCtx(ctx context.Context, query *user.G
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cacheKey = newSignedInUserCacheKey(result.OrgID, query.UserID)
|
||||
cacheKey := newSignedInUserCacheKey(result.OrgID, result.UserID)
|
||||
s.cacheService.Set(cacheKey, *result, time.Second*5)
|
||||
return result, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user