Fix lookupCache to work when idp has more users (#1321)

This commit is contained in:
Yury Gargay 2023-11-20 16:47:11 +01:00 committed by GitHub
parent d78b7e5d93
commit afece95ae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1082,9 +1082,6 @@ func (am *DefaultAccountManager) loadAccount(_ context.Context, accountID interf
if user.IsServiceUser { if user.IsServiceUser {
continue continue
} }
if user.Issued == UserIssuedIntegration {
continue
}
datum, ok := dataMap[user.Id] datum, ok := dataMap[user.Id]
if !ok { if !ok {
log.Warnf("user %s not found in IDP", user.Id) log.Warnf("user %s not found in IDP", user.Id)
@ -1191,19 +1188,20 @@ func (am *DefaultAccountManager) lookupCache(accountUsers map[string]struct{}, a
userDataMap[datum.ID] = struct{}{} userDataMap[datum.ID] = struct{}{}
} }
// check whether we need to reload the cache // the accountUsers ID list of non integration users from store, we check if cache has all of them
// the accountUsers ID list is the source of truth and all the users should be in the cache // as result of for loop knownUsersCount will have number of users are not presented in the cashed
reload := len(accountUsers) != len(data) knownUsersCount := len(accountUsers)
for user := range accountUsers { for user := range accountUsers {
if _, ok := userDataMap[user]; !ok { if _, ok := userDataMap[user]; ok {
reload = true knownUsersCount--
log.Debugf("idp cache doesn't have user %s", user) continue
break
} }
log.Debugf("cache doesn't know about %s user", user)
} }
if reload { // if we know users that are not yet in cache more likely cache is outdated
log.Debugf("reload cache, len(accountUsers) = %d, len(data) = %d", len(accountUsers), len(data)) if knownUsersCount > 0 {
log.Debugf("cache doesn't know about %d users from store, reloading", knownUsersCount)
// reload cache once avoiding loops // reload cache once avoiding loops
data, err = am.refreshCache(accountID) data, err = am.refreshCache(accountID)
if err != nil { if err != nil {