Improve Account cache reload condition (#1319)

To take in consideration that cache may know more users
This commit is contained in:
Yury Gargay 2023-11-20 12:05:32 +01:00 committed by GitHub
parent 52b5a31058
commit 67906f6da5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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)
@ -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{}{}
@ -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 {

View File

@ -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 {