From 8f944f64349be6c434d5e47d9453c85db82d0144 Mon Sep 17 00:00:00 2001 From: Till <2353100+S7evinK@users.noreply.github.com> Date: Tue, 20 Feb 2024 08:38:51 +0100 Subject: [PATCH] Limit filter to `limit/2` for before/after events on `/context` (#3332) Part of https://github.com/matrix-org/dendrite/issues/3224 --- syncapi/routing/context.go | 6 ++++++ syncapi/syncapi_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/syncapi/routing/context.go b/syncapi/routing/context.go index b0c91c40..b136c69a 100644 --- a/syncapi/routing/context.go +++ b/syncapi/routing/context.go @@ -110,6 +110,7 @@ func Context( } stateFilter := synctypes.StateFilter{ + Limit: filter.Limit, NotSenders: filter.NotSenders, NotTypes: filter.NotTypes, Senders: filter.Senders, @@ -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") diff --git a/syncapi/syncapi_test.go b/syncapi/syncapi_test.go index 0a2c38ab..0392f209 100644 --- a/syncapi/syncapi_test.go +++ b/syncapi/syncapi_test.go @@ -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",