aboutsummaryrefslogtreecommitdiff
path: root/syncapi/routing
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-05-01 11:01:34 +0100
committerGitHub <noreply@github.com>2020-05-01 11:01:34 +0100
commitb28674435e3024bf0e4723a9cf53180607f2045e (patch)
treef1e7d1f717624bb8419250626109ac16c52af103 /syncapi/routing
parente15f6676ac3f76ec2ef679c2df300d6a8e7e668f (diff)
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
Diffstat (limited to 'syncapi/routing')
-rw-r--r--syncapi/routing/messages.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go
index 5105e224..d7e39704 100644
--- a/syncapi/routing/messages.go
+++ b/syncapi/routing/messages.go
@@ -229,14 +229,14 @@ func (r *messagesReq) retrieveEvents() (
// change the way topological positions are defined (as depth isn't the most
// reliable way to define it), it would be easier and less troublesome to
// only have to change it in one place, i.e. the database.
- startPos, err := r.db.EventPositionInTopology(
+ startPos, startStreamPos, err := r.db.EventPositionInTopology(
r.ctx, events[0].EventID(),
)
if err != nil {
err = fmt.Errorf("EventPositionInTopology: for start event %s: %w", events[0].EventID(), err)
return
}
- endPos, err := r.db.EventPositionInTopology(
+ endPos, endStreamPos, err := r.db.EventPositionInTopology(
r.ctx, events[len(events)-1].EventID(),
)
if err != nil {
@@ -246,10 +246,10 @@ func (r *messagesReq) retrieveEvents() (
// Generate pagination tokens to send to the client using the positions
// retrieved previously.
start = types.NewPaginationTokenFromTypeAndPosition(
- types.PaginationTokenTypeTopology, startPos, 0,
+ types.PaginationTokenTypeTopology, startPos, startStreamPos,
)
end = types.NewPaginationTokenFromTypeAndPosition(
- types.PaginationTokenTypeTopology, endPos, 0,
+ types.PaginationTokenTypeTopology, endPos, endStreamPos,
)
if r.backwardOrdering {
@@ -407,13 +407,13 @@ func setToDefault(
// go 1 earlier than the first event so we correctly fetch the earliest event
to = types.NewPaginationTokenFromTypeAndPosition(types.PaginationTokenTypeTopology, 0, 0)
} else {
- var pos types.StreamPosition
- pos, err = db.MaxTopologicalPosition(ctx, roomID)
+ var pos, stream types.StreamPosition
+ pos, stream, err = db.MaxTopologicalPosition(ctx, roomID)
if err != nil {
return
}
- to = types.NewPaginationTokenFromTypeAndPosition(types.PaginationTokenTypeTopology, pos, 0)
+ to = types.NewPaginationTokenFromTypeAndPosition(types.PaginationTokenTypeTopology, pos, stream)
}
return