Reduce usage of tmpAccounts to only location where it is needed imports

On import handle it with priority as in non recursive situations, it
won't be present.
This commit is contained in:
Matthias Hanel
2020-07-27 16:55:54 -04:00
parent 37692d2cf9
commit 00faefec06
3 changed files with 8 additions and 5 deletions

View File

@@ -2353,7 +2353,14 @@ func (s *Server) UpdateAccountClaims(a *Account, ac *jwt.AccountClaims) {
}
}
for _, i := range ac.Imports {
acc, err := s.lookupAccount(i.Account)
// check tmpAccounts with priority
acc := (*Account)(nil)
err := error(nil)
if v, ok := s.tmpAccounts.Load(i.Account); ok {
acc = v.(*Account)
} else {
acc, err = s.lookupAccount(i.Account)
}
if acc == nil || err != nil {
s.Errorf("Can't locate account [%s] for import of [%v] %s (err=%v)", i.Account, i.Subject, i.Type, err)
continue

View File

@@ -1011,8 +1011,6 @@ func (c *client) processRemoteSub(argo []byte, hasOrigin bool) (err error) {
acc, _ = srv.LookupAccount(accountName)
} else if v, ok := srv.accounts.Load(accountName); ok {
acc = v.(*Account)
} else if v, ok := srv.tmpAccounts.Load(accountName); ok {
acc = v.(*Account)
}
if acc == nil {
expire := false

View File

@@ -1124,8 +1124,6 @@ func (s *Server) lookupAccount(name string) (*Account, error) {
var acc *Account
if v, ok := s.accounts.Load(name); ok {
acc = v.(*Account)
} else if v, ok := s.tmpAccounts.Load(name); ok {
acc = v.(*Account)
}
if acc != nil {
// If we are expired and we have a resolver, then