From f2f094e7f06cab26ec1b15954099747117b576ce Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 27 Jul 2021 14:03:08 +0100 Subject: [PATCH] Tweaks --- syncapi/storage/shared/sync_pdu.go | 4 ++-- syncapi/storage/shared/syncserver.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/syncapi/storage/shared/sync_pdu.go b/syncapi/storage/shared/sync_pdu.go index 2e9a2ba2..bbc46acb 100644 --- a/syncapi/storage/shared/sync_pdu.go +++ b/syncapi/storage/shared/sync_pdu.go @@ -134,7 +134,7 @@ func (d *Database) addRoomDeltaToResponse( } recentEvents := d.StreamEventsToEvents(device, recentStreamEvents) delta.StateEvents = removeDuplicates(delta.StateEvents, recentEvents) // roll back - prevBatch, err := d.GetBackwardTopologyPos(ctx, recentStreamEvents) + prevBatch, err := d.getBackwardTopologyPos(ctx, txn, recentStreamEvents) if err != nil { return err } @@ -246,7 +246,7 @@ func (d *Database) getJoinResponseForCompleteSync( var prevBatch *types.TopologyToken if len(recentStreamEvents) > 0 { var backwardTopologyPos, backwardStreamPos types.StreamPosition - backwardTopologyPos, backwardStreamPos, err = d.PositionInTopology(ctx, recentStreamEvents[0].EventID()) + backwardTopologyPos, backwardStreamPos, err = d.Topology.SelectPositionInTopology(ctx, txn, recentStreamEvents[0].EventID()) if err != nil { return } diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index 49c29257..d583aaea 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -551,12 +551,19 @@ func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, reda func (d *Database) GetBackwardTopologyPos( ctx context.Context, events []types.StreamEvent, +) (types.TopologyToken, error) { + return d.getBackwardTopologyPos(ctx, nil, events) +} + +func (d *Database) getBackwardTopologyPos( + ctx context.Context, txn *sql.Tx, + events []types.StreamEvent, ) (types.TopologyToken, error) { zeroToken := types.TopologyToken{} if len(events) == 0 { return zeroToken, nil } - pos, spos, err := d.Topology.SelectPositionInTopology(ctx, nil, events[0].EventID()) + pos, spos, err := d.Topology.SelectPositionInTopology(ctx, txn, events[0].EventID()) if err != nil { return zeroToken, err }