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