Skip to content

Commit

Permalink
Improve Account cache reload condition (#1319)
Browse files Browse the repository at this point in the history
To take in consideration that cache may know more users
  • Loading branch information
surik committed Dec 14, 2023
1 parent a3716c0 commit 528acf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@ func (am *DefaultAccountManager) loadAccount(_ context.Context, accountID interf
if user.IsServiceUser {
continue
}
if user.Issued == UserIssuedIntegration {
continue
}
datum, ok := dataMap[user.Id]
if !ok {
log.Warnf("user %s not found in IDP", user.Id)
Expand Down Expand Up @@ -1115,7 +1118,7 @@ func (am *DefaultAccountManager) lookupUserInCache(userID string, account *Accou
if user.IsServiceUser {
continue
}
if user.Issued == UserIssuedIntegration && user.LastLogin.IsZero() {
if user.Issued == UserIssuedIntegration {
continue
}
users[user.Id] = struct{}{}
Expand Down Expand Up @@ -1194,10 +1197,13 @@ func (am *DefaultAccountManager) lookupCache(accountUsers map[string]struct{}, a
for user := range accountUsers {
if _, ok := userDataMap[user]; !ok {
reload = true
log.Debugf("idp cache doesn't have user %s", user)
break
}
}

if reload {
log.Debugf("reload cache, len(accountUsers) = %d, len(data) = %d", len(accountUsers), len(data))
// reload cache once avoiding loops
data, err = am.refreshCache(accountID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion management/server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func (am *DefaultAccountManager) GetUsersFromAccount(accountID, userID string) (
users := make(map[string]struct{}, len(account.Users))
usersFromIntegration := make([]*idp.UserData, 0)
for _, user := range account.Users {
if user.Issued == UserIssuedIntegration && user.LastLogin.IsZero() {
if user.Issued == UserIssuedIntegration {
key := user.IntegrationReference.CacheKey(accountID, user.Id)
info, err := am.externalCacheManager.Get(am.ctx, key)
if err != nil {
Expand Down

0 comments on commit 528acf7

Please sign in to comment.