Improve updateAccountPeers by bypassing AM and using account directly (#1193)

Improve updateAccountPeers performance by bypassing AM and using the account directly
This commit is contained in:
Yury Gargay
2023-10-04 15:08:50 +02:00
committed by GitHub
parent 26bbc33e7a
commit 9131069d12
9 changed files with 49 additions and 77 deletions

View File

@@ -290,10 +290,7 @@ func (am *DefaultAccountManager) MarkPeerConnected(peerPubKey string, connected
if oldStatus.LoginExpired {
// we need to update other peers because when peer login expires all other peers are notified to disconnect from
// the expired one. Here we notify them that connection is now allowed again.
err = am.updateAccountPeers(account)
if err != nil {
return err
}
am.updateAccountPeers(account)
}
return nil
@@ -364,10 +361,7 @@ func (am *DefaultAccountManager) UpdatePeer(accountID, userID string, update *Pe
return nil, err
}
err = am.updateAccountPeers(account)
if err != nil {
return nil, err
}
am.updateAccountPeers(account)
return peer, nil
}
@@ -433,7 +427,9 @@ func (am *DefaultAccountManager) DeletePeer(accountID, peerID, userID string) er
return err
}
return am.updateAccountPeers(account)
am.updateAccountPeers(account)
return nil
}
// GetPeerByIP returns peer by its IP
@@ -622,10 +618,7 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *Peer) (*
opEvent.Meta = newPeer.EventMeta(am.GetDNSDomain())
am.storeEvent(opEvent.InitiatorID, opEvent.TargetID, opEvent.AccountID, opEvent.Activity, opEvent.Meta)
err = am.updateAccountPeers(account)
if err != nil {
return nil, nil, err
}
am.updateAccountPeers(account)
networkMap := account.GetPeerNetworkMap(newPeer.ID, am.dnsDomain)
return newPeer, networkMap, nil
@@ -740,10 +733,7 @@ func (am *DefaultAccountManager) LoginPeer(login PeerLogin) (*Peer, *NetworkMap,
}
if updateRemotePeers {
err = am.updateAccountPeers(account)
if err != nil {
return nil, nil, err
}
am.updateAccountPeers(account)
}
return peer, account.GetPeerNetworkMap(peer.ID, am.dnsDomain), nil
}
@@ -817,10 +807,7 @@ func (am *DefaultAccountManager) checkAndUpdatePeerSSHKey(peer *Peer, account *A
}
// trigger network map update
err = am.updateAccountPeers(account)
if err != nil {
return nil, err
}
am.updateAccountPeers(account)
return peer, nil
}
@@ -865,7 +852,9 @@ func (am *DefaultAccountManager) UpdatePeerSSHKey(peerID string, sshKey string)
}
// trigger network map update
return am.updateAccountPeers(account)
am.updateAccountPeers(account)
return nil
}
// GetPeer for a given accountID, peerID and userID error if not found.
@@ -922,18 +911,12 @@ func updatePeerMeta(peer *Peer, meta PeerSystemMeta, account *Account) (*Peer, b
// updateAccountPeers updates all peers that belong to an account.
// Should be called when changes have to be synced to peers.
func (am *DefaultAccountManager) updateAccountPeers(account *Account) error {
func (am *DefaultAccountManager) updateAccountPeers(account *Account) {
peers := account.GetPeers()
for _, peer := range peers {
remotePeerNetworkMap, err := am.GetNetworkMap(peer.ID)
if err != nil {
return err
}
remotePeerNetworkMap := account.GetPeerNetworkMap(peer.ID, am.dnsDomain)
update := toSyncResponse(nil, peer, nil, remotePeerNetworkMap, am.GetDNSDomain())
am.peersUpdateManager.SendUpdate(peer.ID, &UpdateMessage{Update: update})
}
return nil
}