Do nort send notifications if nothing changed.

This commit is contained in:
Sascha L. Teichmann 2014-09-17 17:34:03 +02:00
parent 29845a259d
commit 51626a1371

View File

@ -31,7 +31,6 @@ func (ct *ChangeTracker) BlockChanged(key []byte) {
log.Printf("decoding key failed: %s", err)
return
}
log.Printf("changed block: %v", coord)
ct.mutex.Lock()
ct.changes[quantizedXZ{X: coord.X / 16, Z: coord.Z / 16}] = true
ct.mutex.Unlock()
@ -40,10 +39,17 @@ func (ct *ChangeTracker) BlockChanged(key []byte) {
func (ct *ChangeTracker) FlushChanges(url string) (err error) {
log.Println("change flush triggered")
var oldChanges map[quantizedXZ]bool
var sendNotification bool
ct.mutex.Lock()
oldChanges = ct.changes
if len(oldChanges) > 0 {
sendNotification = true
ct.changes = make(map[quantizedXZ]bool)
}
ct.mutex.Unlock()
if !sendNotification {
return
}
go func() {
changes := make([]quantizedXZ, len(oldChanges))
i := 0