Skip to content

Commit

Permalink
send all peer updates in a separate go routine
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer committed Dec 20, 2024
1 parent ddc365f commit d73491a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st

if removedGroupAffectsPeers || newGroupsAffectsPeers {
log.WithContext(ctx).Tracef("user %s: JWT group membership changed, updating account peers", claims.UserId)
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}
}

Expand Down Expand Up @@ -1662,7 +1662,7 @@ func (am *DefaultAccountManager) CheckUserAccessByJWTGroups(ctx context.Context,

func (am *DefaultAccountManager) onPeersInvalidated(ctx context.Context, accountID string) {
log.WithContext(ctx).Debugf("validated peers has been invalidated for account %s", accountID)
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

func (am *DefaultAccountManager) FindExistingPostureCheck(accountID string, checks *posture.ChecksDefinition) (*posture.Checks, error) {
Expand Down
2 changes: 1 addition & 1 deletion management/server/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (am *DefaultAccountManager) SaveDNSSettings(ctx context.Context, accountID
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions management/server/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (am *DefaultAccountManager) SaveGroups(ctx context.Context, accountID, user
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down Expand Up @@ -296,7 +296,7 @@ func (am *DefaultAccountManager) GroupAddPeer(ctx context.Context, accountID, gr
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down Expand Up @@ -337,7 +337,7 @@ func (am *DefaultAccountManager) GroupAddResource(ctx context.Context, accountID
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down Expand Up @@ -378,7 +378,7 @@ func (am *DefaultAccountManager) GroupDeletePeer(ctx context.Context, accountID,
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down Expand Up @@ -419,7 +419,7 @@ func (am *DefaultAccountManager) GroupDeleteResource(ctx context.Context, accoun
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions management/server/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (am *DefaultAccountManager) CreateNameServerGroup(ctx context.Context, acco
am.StoreEvent(ctx, userID, newNSGroup.ID, accountID, activity.NameserverGroupCreated, newNSGroup.EventMeta())

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return newNSGroup.Copy(), nil
Expand Down Expand Up @@ -143,7 +143,7 @@ func (am *DefaultAccountManager) SaveNameServerGroup(ctx context.Context, accoun
am.StoreEvent(ctx, userID, nsGroupToSave.ID, accountID, activity.NameserverGroupUpdated, nsGroupToSave.EventMeta())

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down Expand Up @@ -190,7 +190,7 @@ func (am *DefaultAccountManager) DeleteNameServerGroup(ctx context.Context, acco
am.StoreEvent(ctx, userID, nsGroup.ID, accountID, activity.NameserverGroupDeleted, nsGroup.EventMeta())

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions management/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
}

if peerLabelUpdated || requiresPeerUpdates {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return peer, nil
Expand Down Expand Up @@ -353,7 +353,7 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down Expand Up @@ -611,7 +611,7 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s
}

if newGroupsAffectsPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

approvedPeersMap, err := am.GetValidatedPeers(account)
Expand Down Expand Up @@ -839,7 +839,7 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin)
}

if updateRemotePeers || isStatusChanged || (updated && len(postureChecks) > 0) {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return am.getValidatedPeerWithMap(ctx, isRequiresApproval, account, peer)
Expand Down
4 changes: 2 additions & 2 deletions management/server/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (am *DefaultAccountManager) SavePolicy(ctx context.Context, accountID, user
am.StoreEvent(ctx, userID, policy.ID, accountID, action, policy.EventMeta())

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return policy, nil
Expand Down Expand Up @@ -135,7 +135,7 @@ func (am *DefaultAccountManager) DeletePolicy(ctx context.Context, accountID, po
am.StoreEvent(ctx, userID, policyID, accountID, activity.PolicyRemoved, policy.EventMeta())

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion management/server/posture_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (am *DefaultAccountManager) SavePostureChecks(ctx context.Context, accountI
am.StoreEvent(ctx, userID, postureChecks.ID, accountID, action, postureChecks.EventMeta())

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return postureChecks, nil
Expand Down
6 changes: 3 additions & 3 deletions management/server/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (am *DefaultAccountManager) CreateRoute(ctx context.Context, accountID stri
}

if am.isRouteChangeAffectPeers(account, &newRoute) {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

am.StoreEvent(ctx, userID, string(newRoute.ID), accountID, activity.RouteCreated, newRoute.EventMeta())
Expand Down Expand Up @@ -297,7 +297,7 @@ func (am *DefaultAccountManager) SaveRoute(ctx context.Context, accountID, userI
}

if am.isRouteChangeAffectPeers(account, oldRoute) || am.isRouteChangeAffectPeers(account, routeToSave) {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

am.StoreEvent(ctx, userID, string(routeToSave.ID), accountID, activity.RouteUpdated, routeToSave.EventMeta())
Expand Down Expand Up @@ -329,7 +329,7 @@ func (am *DefaultAccountManager) DeleteRoute(ctx context.Context, accountID stri
am.StoreEvent(ctx, userID, string(routy.ID), accountID, activity.RouteRemoved, routy.EventMeta())

if am.isRouteChangeAffectPeers(account, routy) {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion management/server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ func (am *DefaultAccountManager) DeleteRegularUsers(ctx context.Context, account
}

if updateAccountPeers {
am.UpdateAccountPeers(ctx, accountID)
go am.UpdateAccountPeers(ctx, accountID)
}

for targetUserID, meta := range deletedUsersMeta {
Expand Down

0 comments on commit d73491a

Please sign in to comment.