mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 14:12:47 +00:00
Correctly generate backpagination tokens for events which have the same depth (#996)
* Correctly generate backpagination tokens for events which have the same depth With tests. Unfortunately the code around here is hard to understand. There will be a subsequent PR which fixes this up now that we have a test harness in place. * Add postgres impl * More linting * Fix psql statement so it actually works
This commit is contained in:
parent
e15f6676ac
commit
b28674435e
10 changed files with 238 additions and 80 deletions
|
@ -159,7 +159,7 @@ func (d *SyncServerDatasource) WriteEvent(
|
|||
}
|
||||
pduPosition = pos
|
||||
|
||||
if err = d.topology.insertEventInTopology(ctx, ev); err != nil {
|
||||
if err = d.topology.insertEventInTopology(ctx, ev, pos); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -240,12 +240,13 @@ func (d *SyncServerDatasource) GetEventsInRange(
|
|||
if from.Type == types.PaginationTokenTypeTopology {
|
||||
// Determine the backward and forward limit, i.e. the upper and lower
|
||||
// limits to the selection in the room's topology, from the direction.
|
||||
var backwardLimit, forwardLimit types.StreamPosition
|
||||
var backwardLimit, forwardLimit, forwardMicroLimit types.StreamPosition
|
||||
if backwardOrdering {
|
||||
// Backward ordering is antichronological (latest event to oldest
|
||||
// one).
|
||||
backwardLimit = to.PDUPosition
|
||||
forwardLimit = from.PDUPosition
|
||||
forwardMicroLimit = from.EDUTypingPosition
|
||||
} else {
|
||||
// Forward ordering is chronological (oldest event to latest one).
|
||||
backwardLimit = from.PDUPosition
|
||||
|
@ -255,7 +256,7 @@ func (d *SyncServerDatasource) GetEventsInRange(
|
|||
// Select the event IDs from the defined range.
|
||||
var eIDs []string
|
||||
eIDs, err = d.topology.selectEventIDsInRange(
|
||||
ctx, roomID, backwardLimit, forwardLimit, limit, !backwardOrdering,
|
||||
ctx, roomID, backwardLimit, forwardLimit, forwardMicroLimit, limit, !backwardOrdering,
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -301,7 +302,7 @@ func (d *SyncServerDatasource) BackwardExtremitiesForRoom(
|
|||
|
||||
func (d *SyncServerDatasource) MaxTopologicalPosition(
|
||||
ctx context.Context, roomID string,
|
||||
) (types.StreamPosition, error) {
|
||||
) (depth types.StreamPosition, stream types.StreamPosition, err error) {
|
||||
return d.topology.selectMaxPositionInTopology(ctx, roomID)
|
||||
}
|
||||
|
||||
|
@ -318,8 +319,13 @@ func (d *SyncServerDatasource) EventsAtTopologicalPosition(
|
|||
|
||||
func (d *SyncServerDatasource) EventPositionInTopology(
|
||||
ctx context.Context, eventID string,
|
||||
) (types.StreamPosition, error) {
|
||||
return d.topology.selectPositionInTopology(ctx, eventID)
|
||||
) (depth types.StreamPosition, stream types.StreamPosition, err error) {
|
||||
depth, err = d.topology.selectPositionInTopology(ctx, eventID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
stream, err = d.events.selectStreamPositionForEventID(ctx, eventID)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SyncServerDatasource) SyncStreamPosition(ctx context.Context) (types.StreamPosition, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue