Skip to content

Commit

Permalink
Limit filter to limit/2 for before/after events on /context (#3332)
Browse files Browse the repository at this point in the history
Part of #3224
  • Loading branch information
S7evinK committed Feb 20, 2024
1 parent ecb7b38 commit 8f944f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit 8f944f6

Please sign in to comment.