|
@ -87,6 +87,8 @@ func (p *Publisher) Publish(devices ...models.Device) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unwaitMap := make(map[int]bool) |
|
|
|
|
|
|
|
|
p.mu.Lock() |
|
|
p.mu.Lock() |
|
|
defer p.mu.Unlock() |
|
|
defer p.mu.Unlock() |
|
|
|
|
|
|
|
@ -106,10 +108,14 @@ func (p *Publisher) Publish(devices ...models.Device) { |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
p.pending[device.BridgeID] = append(p.pending[device.BridgeID], device) |
|
|
p.pending[device.BridgeID] = append(p.pending[device.BridgeID], device) |
|
|
if p.waiting[device.BridgeID] != nil { |
|
|
|
|
|
close(p.waiting[device.BridgeID]) |
|
|
|
|
|
p.waiting[device.BridgeID] = nil |
|
|
|
|
|
|
|
|
unwaitMap[device.BridgeID] = true |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for bridgeID := range unwaitMap { |
|
|
|
|
|
if p.waiting[bridgeID] != nil { |
|
|
|
|
|
close(p.waiting[bridgeID]) |
|
|
|
|
|
p.waiting[bridgeID] = nil |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -124,11 +130,16 @@ func (p *Publisher) Run() { |
|
|
ticker := time.NewTicker(time.Millisecond * 100) |
|
|
ticker := time.NewTicker(time.Millisecond * 100) |
|
|
deleteList := make([]int, 0, 8) |
|
|
deleteList := make([]int, 0, 8) |
|
|
updatedList := make([]models.Device, 0, 16) |
|
|
updatedList := make([]models.Device, 0, 16) |
|
|
|
|
|
unwaitMap := make(map[int]bool) |
|
|
|
|
|
|
|
|
for range ticker.C { |
|
|
for range ticker.C { |
|
|
deleteList = deleteList[:0] |
|
|
deleteList = deleteList[:0] |
|
|
updatedList = updatedList[:0] |
|
|
updatedList = updatedList[:0] |
|
|
|
|
|
|
|
|
|
|
|
for key := range unwaitMap { |
|
|
|
|
|
delete(unwaitMap, key) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
p.mu.Lock() |
|
|
p.mu.Lock() |
|
|
for i, scene := range p.scenes { |
|
|
for i, scene := range p.scenes { |
|
|
if (!scene.endTime.IsZero() && time.Now().After(scene.endTime)) || scene.Empty() { |
|
|
if (!scene.endTime.IsZero() && time.Now().After(scene.endTime)) || scene.Empty() { |
|
@ -160,9 +171,13 @@ func (p *Publisher) Run() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
p.pending[device.BridgeID] = append(p.pending[device.BridgeID], device) |
|
|
p.pending[device.BridgeID] = append(p.pending[device.BridgeID], device) |
|
|
if p.waiting[device.BridgeID] != nil { |
|
|
|
|
|
close(p.waiting[device.BridgeID]) |
|
|
|
|
|
p.waiting[device.BridgeID] = nil |
|
|
|
|
|
|
|
|
unwaitMap[device.BridgeID] = true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for bridgeID := range unwaitMap { |
|
|
|
|
|
if p.waiting[bridgeID] != nil { |
|
|
|
|
|
close(p.waiting[bridgeID]) |
|
|
|
|
|
p.waiting[bridgeID] = nil |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
p.mu.Unlock() |
|
|
p.mu.Unlock() |
|
@ -270,8 +285,8 @@ func (p *Publisher) runBridge(id int) { |
|
|
p.mu.Lock() |
|
|
p.mu.Lock() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updates := p.pending[id] |
|
|
|
|
|
p.pending[id] = p.pending[id][:0:0] |
|
|
|
|
|
|
|
|
updates := append(p.pending[id][:0:0], p.pending[id]...) |
|
|
|
|
|
p.pending[id] = p.pending[id][:0] |
|
|
p.mu.Unlock() |
|
|
p.mu.Unlock() |
|
|
|
|
|
|
|
|
// Only allow the latest update per device (this avoids slow bridges causing a backlog of cations).
|
|
|
// Only allow the latest update per device (this avoids slow bridges causing a backlog of cations).
|
|
|