aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/sqlite3/syncserver.go
diff options
context:
space:
mode:
Diffstat (limited to 'syncapi/storage/sqlite3/syncserver.go')
-rw-r--r--syncapi/storage/sqlite3/syncserver.go24
1 files changed, 10 insertions, 14 deletions
diff --git a/syncapi/storage/sqlite3/syncserver.go b/syncapi/storage/sqlite3/syncserver.go
index bdf943e0..7e8e4ff5 100644
--- a/syncapi/storage/sqlite3/syncserver.go
+++ b/syncapi/storage/sqlite3/syncserver.go
@@ -374,12 +374,7 @@ func (d *SyncServerDatasource) EventsAtTopologicalPosition(
func (d *SyncServerDatasource) EventPositionInTopology(
ctx context.Context, eventID string,
) (depth types.StreamPosition, stream types.StreamPosition, err error) {
- depth, err = d.topology.selectPositionInTopology(ctx, nil, eventID)
- if err != nil {
- return
- }
- stream, err = d.events.selectStreamPositionForEventID(ctx, eventID)
- return
+ return d.topology.selectPositionInTopology(ctx, nil, eventID)
}
// SyncStreamPosition returns the latest position in the sync stream. Returns 0 if there are no events yet.
@@ -657,8 +652,8 @@ func (d *SyncServerDatasource) getResponseWithPDUsForCompleteSync(
// Retrieve the backward topology position, i.e. the position of the
// oldest event in the room's topology.
- var backwardTopologyPos types.StreamPosition
- backwardTopologyPos, err = d.topology.selectPositionInTopology(ctx, txn, recentStreamEvents[0].EventID())
+ var backwardTopologyPos, backwardTopologyStreamPos types.StreamPosition
+ backwardTopologyPos, backwardTopologyStreamPos, err = d.topology.selectPositionInTopology(ctx, txn, recentStreamEvents[0].EventID())
if backwardTopologyPos-1 <= 0 {
backwardTopologyPos = types.StreamPosition(1)
} else {
@@ -671,7 +666,7 @@ func (d *SyncServerDatasource) getResponseWithPDUsForCompleteSync(
stateEvents = removeDuplicates(stateEvents, recentEvents)
jr := types.NewJoinResponse()
jr.Timeline.PrevBatch = types.NewPaginationTokenFromTypeAndPosition(
- types.PaginationTokenTypeTopology, backwardTopologyPos, 0,
+ types.PaginationTokenTypeTopology, backwardTopologyPos, backwardTopologyStreamPos,
).String()
jr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
jr.Timeline.Limited = true
@@ -818,10 +813,11 @@ func (d *SyncServerDatasource) addInvitesToResponse(
func (d *SyncServerDatasource) getBackwardTopologyPos(
ctx context.Context, txn *sql.Tx,
events []types.StreamEvent,
-) (pos types.StreamPosition) {
+) (pos, spos types.StreamPosition) {
if len(events) > 0 {
- pos, _ = d.topology.selectPositionInTopology(ctx, txn, events[0].EventID())
+ pos, spos, _ = d.topology.selectPositionInTopology(ctx, txn, events[0].EventID())
}
+ // TODO: I have no idea what this is doing.
if pos-1 <= 0 {
pos = types.StreamPosition(1)
} else {
@@ -859,14 +855,14 @@ func (d *SyncServerDatasource) addRoomDeltaToResponse(
}
recentEvents := d.StreamEventsToEvents(device, recentStreamEvents)
delta.stateEvents = removeDuplicates(delta.stateEvents, recentEvents)
- backwardTopologyPos := d.getBackwardTopologyPos(ctx, txn, recentStreamEvents)
+ backwardTopologyPos, backwardStreamPos := d.getBackwardTopologyPos(ctx, txn, recentStreamEvents)
switch delta.membership {
case gomatrixserverlib.Join:
jr := types.NewJoinResponse()
jr.Timeline.PrevBatch = types.NewPaginationTokenFromTypeAndPosition(
- types.PaginationTokenTypeTopology, backwardTopologyPos, 0,
+ types.PaginationTokenTypeTopology, backwardTopologyPos, backwardStreamPos,
).String()
jr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
jr.Timeline.Limited = false // TODO: if len(events) >= numRecents + 1 and then set limited:true
@@ -879,7 +875,7 @@ func (d *SyncServerDatasource) addRoomDeltaToResponse(
// no longer in the room.
lr := types.NewLeaveResponse()
lr.Timeline.PrevBatch = types.NewPaginationTokenFromTypeAndPosition(
- types.PaginationTokenTypeTopology, backwardTopologyPos, 0,
+ types.PaginationTokenTypeTopology, backwardTopologyPos, backwardStreamPos,
).String()
lr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
lr.Timeline.Limited = false // TODO: if len(events) >= numRecents + 1 and then set limited:true