diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2022-10-28 13:40:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-28 13:40:51 +0200 |
commit | 69aff372f3e0ac5d98292e1e5382b66b162037ea (patch) | |
tree | b262165bb1bc6314311f3e2997eb2768baf9ee24 /syncapi/streams | |
parent | 0782011f54dca98d96a8c5a78f68569ed045892a (diff) |
Limit recent events when going backwards (#2840)
If we're going backwards, we were selecting potentially thousands of
events, which in turn were fed to history visibility checks, resulting
in bad sync performance.
Diffstat (limited to 'syncapi/streams')
-rw-r--r-- | syncapi/streams/stream_pdu.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/syncapi/streams/stream_pdu.go b/syncapi/streams/stream_pdu.go index 87f7a064..3ab0f4ed 100644 --- a/syncapi/streams/stream_pdu.go +++ b/syncapi/streams/stream_pdu.go @@ -216,6 +216,9 @@ func (p *PDUStreamProvider) IncrementalSync( return newPos } +// Limit the recent events to X when going backwards +const recentEventBackwardsLimit = 100 + // nolint:gocyclo func (p *PDUStreamProvider) addRoomDeltaToResponse( ctx context.Context, @@ -229,9 +232,15 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse( ) (types.StreamPosition, error) { originalLimit := eventFilter.Limit - if r.Backwards { - eventFilter.Limit = int(r.From - r.To) + // If we're going backwards, grep at least X events, this is mostly to satisfy Sytest + if r.Backwards && originalLimit < recentEventBackwardsLimit { + eventFilter.Limit = recentEventBackwardsLimit // TODO: Figure out a better way + diff := r.From - r.To + if diff > 0 && diff < recentEventBackwardsLimit { + eventFilter.Limit = int(diff) + } } + recentStreamEvents, limited, err := snapshot.RecentEvents( ctx, delta.RoomID, r, eventFilter, true, true, |