mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
build cache only once
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/types"
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,16 +19,7 @@ func (am *DefaultAccountManager) enrichAccountFromHolder(account *types.Account)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *DefaultAccountManager) getAccountFromHolder(accountID string) *types.Account {
|
func (am *DefaultAccountManager) getAccountFromHolder(accountID string) *types.Account {
|
||||||
a := am.holder.GetAccount(accountID)
|
return am.holder.GetAccount(accountID)
|
||||||
if a != nil {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
account, err := am.requestBuffer.GetAccountWithBackpressure(context.Background(), accountID)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
am.holder.AddAccount(account)
|
|
||||||
return account
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *DefaultAccountManager) updateAccountInHolder(account *types.Account) {
|
func (am *DefaultAccountManager) updateAccountInHolder(account *types.Account) {
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ func (am *DefaultAccountManager) onPeerDeletedUpdNetworkMapCache(account *types.
|
|||||||
|
|
||||||
func (am *DefaultAccountManager) updatePeerInNetworkMapCache(accountId string, peer *nbpeer.Peer) {
|
func (am *DefaultAccountManager) updatePeerInNetworkMapCache(accountId string, peer *nbpeer.Peer) {
|
||||||
account := am.getAccountFromHolder(accountId)
|
account := am.getAccountFromHolder(accountId)
|
||||||
|
if account == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
account.UpdatePeerInNetworkMapCache(peer)
|
account.UpdatePeerInNetworkMapCache(peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
@@ -88,6 +89,7 @@ type Account struct {
|
|||||||
Onboarding AccountOnboarding `gorm:"foreignKey:AccountID;references:id;constraint:OnDelete:CASCADE"`
|
Onboarding AccountOnboarding `gorm:"foreignKey:AccountID;references:id;constraint:OnDelete:CASCADE"`
|
||||||
|
|
||||||
NetworkMapCache *NetworkMapBuilder `gorm:"-"`
|
NetworkMapCache *NetworkMapBuilder `gorm:"-"`
|
||||||
|
nmapInitOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// this class is used by gorm only
|
// this class is used by gorm only
|
||||||
|
|||||||
@@ -846,10 +846,9 @@ func peerIsNameserver(peer *nbpeer.Peer, nsGroup *nbdns.NameServerGroup) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) initNetworkMapBuilder(validatedPeers map[string]struct{}) {
|
func (a *Account) initNetworkMapBuilder(validatedPeers map[string]struct{}) {
|
||||||
if a.NetworkMapCache != nil {
|
a.nmapInitOnce.Do(func() {
|
||||||
return
|
a.NetworkMapCache = NewNetworkMapBuilder(a, validatedPeers)
|
||||||
}
|
})
|
||||||
a.NetworkMapCache = NewNetworkMapBuilder(a, validatedPeers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) InitNetworkMapBuilderIfNeeded(validatedPeers map[string]struct{}) {
|
func (a *Account) InitNetworkMapBuilderIfNeeded(validatedPeers map[string]struct{}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user