Merge pull request #712 from milosgajdos83/route-update

Only emit table event if table.Update actually happens
This commit is contained in:
Asim Aslam 2019-08-29 16:30:27 +01:00 committed by GitHub
commit 690640eeeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,8 +83,10 @@ func (t *table) Delete(r Route) error {
return ErrRouteNotFound return ErrRouteNotFound
} }
delete(t.routes[service], sum) if _, ok := t.routes[service][sum]; ok {
go t.sendEvent(&Event{Type: Delete, Timestamp: time.Now(), Route: r}) delete(t.routes[service], sum)
go t.sendEvent(&Event{Type: Delete, Timestamp: time.Now(), Route: r})
}
return nil return nil
} }
@ -105,8 +107,10 @@ func (t *table) Update(r Route) error {
return nil return nil
} }
t.routes[service][sum] = r if _, ok := t.routes[service][sum]; !ok {
go t.sendEvent(&Event{Type: Update, Timestamp: time.Now(), Route: r}) t.routes[service][sum] = r
go t.sendEvent(&Event{Type: Update, Timestamp: time.Now(), Route: r})
}
return nil return nil
} }