mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 09:47:49 +02:00
Improve Account cache reload condition (#1319)
To take in consideration that cache may know more users
This commit is contained in:
parent
52b5a31058
commit
67906f6da5
@ -1082,6 +1082,9 @@ 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)
|
||||||
@ -1115,7 +1118,7 @@ func (am *DefaultAccountManager) lookupUserInCache(userID string, account *Accou
|
|||||||
if user.IsServiceUser {
|
if user.IsServiceUser {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if user.Issued == UserIssuedIntegration && user.LastLogin.IsZero() {
|
if user.Issued == UserIssuedIntegration {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
users[user.Id] = struct{}{}
|
users[user.Id] = struct{}{}
|
||||||
@ -1194,10 +1197,13 @@ func (am *DefaultAccountManager) lookupCache(accountUsers map[string]struct{}, a
|
|||||||
for user := range accountUsers {
|
for user := range accountUsers {
|
||||||
if _, ok := userDataMap[user]; !ok {
|
if _, ok := userDataMap[user]; !ok {
|
||||||
reload = true
|
reload = true
|
||||||
|
log.Debugf("idp cache doesn't have user %s", user)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if reload {
|
if reload {
|
||||||
|
log.Debugf("reload cache, len(accountUsers) = %d, len(data) = %d", len(accountUsers), len(data))
|
||||||
// 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 {
|
||||||
|
@ -896,7 +896,7 @@ func (am *DefaultAccountManager) GetUsersFromAccount(accountID, userID string) (
|
|||||||
users := make(map[string]struct{}, len(account.Users))
|
users := make(map[string]struct{}, len(account.Users))
|
||||||
usersFromIntegration := make([]*idp.UserData, 0)
|
usersFromIntegration := make([]*idp.UserData, 0)
|
||||||
for _, user := range account.Users {
|
for _, user := range account.Users {
|
||||||
if user.Issued == UserIssuedIntegration && user.LastLogin.IsZero() {
|
if user.Issued == UserIssuedIntegration {
|
||||||
key := user.IntegrationReference.CacheKey(accountID, user.Id)
|
key := user.IntegrationReference.CacheKey(accountID, user.Id)
|
||||||
info, err := am.externalCacheManager.Get(am.ctx, key)
|
info, err := am.externalCacheManager.Get(am.ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user