Fix ordering when backfilling (#1000)

* Fix ordering when backfilling

The problem was that we weren't sorting the returned events
by depth when sending them back to the caller, instead we
were sorting by prev_events which is not the same thing.

* Fixup tests
This commit is contained in:
Kegsay 2020-05-01 16:41:13 +01:00 committed by GitHub
parent f7cfa75886
commit 36bbb25561
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 110 additions and 10 deletions

View file

@ -434,6 +434,7 @@ func (d *SyncServerDatasource) syncPositionTx(
}
sp.PDUPosition = types.StreamPosition(maxEventID)
sp.EDUTypingPosition = types.StreamPosition(d.eduCache.GetLatestSyncPosition())
sp.Type = types.PaginationTokenTypeStream
return
}
@ -658,6 +659,7 @@ func (d *SyncServerDatasource) getResponseWithPDUsForCompleteSync(
backwardTopologyPos = types.StreamPosition(1)
} else {
backwardTopologyPos--
backwardTopologyStreamPos += 1000 // this has to be bigger than the number of events we backfill per request
}
// We don't include a device here as we don't need to send down
@ -817,11 +819,13 @@ func (d *SyncServerDatasource) getBackwardTopologyPos(
if len(events) > 0 {
pos, spos, _ = d.topology.selectPositionInTopology(ctx, txn, events[0].EventID())
}
// TODO: I have no idea what this is doing.
// go to the previous position so we don't pull out the same event twice
// FIXME: This could be done more nicely by being explicit with inclusive/exclusive rules
if pos-1 <= 0 {
pos = types.StreamPosition(1)
} else {
pos = pos - 1
spos += 1000 // this has to be bigger than the number of events we backfill per request
}
return
}