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

Add a default limit to get/sync operations #7858

Merged
merged 5 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions changelog.d/7858.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The default value of `filter_timeline_limit` was changed from -1 (no limit) to 500.
clokep marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ pid_file: DATADIR/homeserver.pid
#gc_thresholds: [700, 10, 10]

# Set the limit on the returned events in the timeline in the get
# and sync operations. The default value is -1, means no upper limit.
# and sync operations. The default value is 500. -1 means no upper limit.
#
# Uncomment the following to increase the limit to 5000.
#
#filter_timeline_limit: 5000

Expand Down
6 changes: 4 additions & 2 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def read_config(self, config, **kwargs):
# errors when attempting to search for messages.
self.enable_search = config.get("enable_search", True)

self.filter_timeline_limit = config.get("filter_timeline_limit", -1)
self.filter_timeline_limit = config.get("filter_timeline_limit", 500)

# Whether we should block invites sent to users on this server
# (other than those sent by local server admins)
Expand Down Expand Up @@ -693,7 +693,9 @@ def generate_config_section(
#gc_thresholds: [700, 10, 10]

# Set the limit on the returned events in the timeline in the get
# and sync operations. The default value is -1, means no upper limit.
# and sync operations. The default value is 500. -1 means no upper limit.
#
# Uncomment the following to increase the limit to 5000.
#
#filter_timeline_limit: 5000

Expand Down
11 changes: 10 additions & 1 deletion synapse/rest/client/v2_alpha/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from synapse.api.errors import InteractiveAuthIncompleteError
from synapse.api.urls import CLIENT_API_PREFIX
from synapse.types import JsonDict

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -51,7 +52,15 @@ def client_patterns(path_regex, releases=(0,), unstable=True, v1=False):
return patterns


def set_timeline_upper_limit(filter_json, filter_timeline_limit):
def set_timeline_upper_limit(filter_json: JsonDict, filter_timeline_limit: int) -> None:
"""
Enforces a maximum limit of a timeline query.

Params:
filter_json: The timeline query to modify.
filter_timeline_limit: The maximum limit to allow, passing -1 will
disable enforcing a maximum limit.
"""
if filter_timeline_limit < 0:
return # no upper limits
timeline = filter_json.get("room", {}).get("timeline", {})
Expand Down