From 0da4a8101d8e53e71e20fb48b52c9fec09772a91 Mon Sep 17 00:00:00 2001 From: Constantin Clauzel Date: Thu, 23 Jul 2015 15:22:32 +0200 Subject: [PATCH] only dispatcher update message to definitions owner when update originiates to a non-owner --- dispatcher/dispatcher.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/dispatcher/dispatcher.go b/dispatcher/dispatcher.go index 5b23b7f..509cfac 100644 --- a/dispatcher/dispatcher.go +++ b/dispatcher/dispatcher.go @@ -123,22 +123,29 @@ func (dispatcher *Dispatcher) removeConnectionAt(index int) { } func (dispatcher *Dispatcher) dispatchUpdate(from int, update *Update) { + fromConnection := dispatcher.connections[from] + fromOwner := false + if _, err := fromConnection.definitions.GetDefinitionForObjectID(update.ObjectID); err == nil { + fromOwner = true + } +mainLoop: for i, connection := range dispatcher.connections { if i == from { continue } - subscribed := false - for _, objectID := range connection.subscriptions { - if objectID == update.ObjectID { - subscribed = true + + if fromOwner == true { + for _, objectID := range connection.subscriptions { + if objectID == update.ObjectID { + connection.InChan <- *update + continue mainLoop + } } - } - if subscribed == false { - if _, err := connection.definitions.GetDefinitionForObjectID(update.ObjectID); err != nil { - continue + } else { + if _, err := connection.definitions.GetDefinitionForObjectID(update.ObjectID); err == nil { + connection.InChan <- *update } } - connection.InChan <- *update } }