Fix off-by-one error

This commit is contained in:
Kegan Dougal 2017-04-07 16:51:40 +01:00
parent 148a868b04
commit cf20835436
2 changed files with 4 additions and 4 deletions

View file

@ -37,7 +37,7 @@ const selectEventsSQL = "" +
"SELECT event_json FROM output_room_events WHERE event_id = ANY($1)"
const selectEventsInRangeSQL = "" +
"SELECT event_json FROM output_room_events WHERE id >= $1 AND id <= $2"
"SELECT event_json FROM output_room_events WHERE id > $1 AND id <= $2"
const selectMaxIDSQL = "" +
"SELECT MAX(id) FROM output_room_events"
@ -96,8 +96,8 @@ func (s *outputRoomEventsStatements) InRange(oldPos, newPos int64) ([]gomatrixse
}
result = append(result, ev)
}
// Expect one event per position, inclusive eg old=3, new=5, expect 3,4,5 so 3 events.
wantNum := (1 + newPos - oldPos)
// Expect one event per position, exclusive of old. eg old=3, new=5, expect 4,5 so 2 events.
wantNum := (newPos - oldPos)
if i != wantNum {
return nil, fmt.Errorf("failed to map all positions to events: (got %d, wanted, %d)", i, wantNum)
}

View file

@ -90,7 +90,7 @@ func (d *SyncServerDatabase) SyncStreamPosition() (int64, error) {
return d.events.MaxID()
}
// EventsInRange returns all events in the given range, inclusive.
// EventsInRange returns all events in the given range, exclusive of oldPos, inclusive of newPos.
func (d *SyncServerDatabase) EventsInRange(oldPos, newPos int64) ([]gomatrixserverlib.Event, error) {
return d.events.InRange(oldPos, newPos)
}