Implement lightweight method to check is peer has update channel (#1351)

Instead of GetAllConnectedPeers that need to traverse the whole
connections map in order to find one channel there.
This commit is contained in:
Yury Gargay
2023-12-05 14:17:56 +01:00
committed by GitHub
parent 45fc89b2c9
commit 27ed88f918
6 changed files with 49 additions and 49 deletions
+1 -6
View File
@@ -35,14 +35,9 @@ func NewPeersHandler(accountManager server.AccountManager, authCfg AuthCfg) *Pee
func (h *PeersHandler) checkPeerStatus(peer *nbpeer.Peer) (*nbpeer.Peer, error) {
peerToReturn := peer.Copy()
if peer.Status.Connected {
statuses, err := h.accountManager.GetAllConnectedPeers()
if err != nil {
return peerToReturn, err
}
// Although we have online status in store we do not yet have an updated channel so have to show it as disconnected
// This may happen after server restart when not all peers are yet connected
if _, connected := statuses[peerToReturn.ID]; !connected {
if !h.accountManager.HasConnectedChannel(peer.ID) {
peerToReturn.Status.Connected = false
}
}