diff --git a/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go b/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go index 1a6e6bf92..581aa5c78 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go +++ b/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go @@ -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) } diff --git a/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go b/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go index 380c6934e..6bb6b69c6 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go +++ b/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go @@ -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) }