Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Limit filter to limit/2 for before/after events on /context #3332

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions syncapi/routing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func Context(
}

stateFilter := synctypes.StateFilter{
Limit: filter.Limit,
NotSenders: filter.NotSenders,
NotTypes: filter.NotTypes,
Senders: filter.Senders,
Expand Down Expand Up @@ -157,6 +158,11 @@ func Context(
}
}

// Limit is split up for before/after events
if filter.Limit > 1 {
filter.Limit = filter.Limit / 2
}

eventsBefore, err := snapshot.SelectContextBeforeEvent(ctx, id, roomID, filter)
if err != nil && err != sql.ErrNoRows {
logrus.WithError(err).Error("unable to fetch before events")
Expand Down
2 changes: 1 addition & 1 deletion syncapi/syncapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ func testContext(t *testing.T, dbType test.DBType) {
},
{
name: "events are not limited",
wantBeforeLength: 7,
wantBeforeLength: 5,
},
{
name: "all events are limited",
Expand Down
Loading