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

Commit 8f944f6

Browse files
authored
Limit filter to limit/2 for before/after events on /context (#3332)
Part of #3224
1 parent ecb7b38 commit 8f944f6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

syncapi/routing/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func Context(
110110
}
111111

112112
stateFilter := synctypes.StateFilter{
113+
Limit: filter.Limit,
113114
NotSenders: filter.NotSenders,
114115
NotTypes: filter.NotTypes,
115116
Senders: filter.Senders,
@@ -157,6 +158,11 @@ func Context(
157158
}
158159
}
159160

161+
// Limit is split up for before/after events
162+
if filter.Limit > 1 {
163+
filter.Limit = filter.Limit / 2
164+
}
165+
160166
eventsBefore, err := snapshot.SelectContextBeforeEvent(ctx, id, roomID, filter)
161167
if err != nil && err != sql.ErrNoRows {
162168
logrus.WithError(err).Error("unable to fetch before events")

syncapi/syncapi_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ func testContext(t *testing.T, dbType test.DBType) {
11361136
},
11371137
{
11381138
name: "events are not limited",
1139-
wantBeforeLength: 7,
1139+
wantBeforeLength: 5,
11401140
},
11411141
{
11421142
name: "all events are limited",

0 commit comments

Comments
 (0)