summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-11-08 11:02:29 +0000
committerErik Johnston <erik@matrix.org>2016-11-08 11:02:29 +0000
commiteeda4e618c0c325e43e82a1d3ac146fbe419b446 (patch)
tree072678c3dfa02598af23e644a7ae3148388257de
parentMerge pull request #1198 from euank/more-ip-blacklist (diff)
downloadsynapse-eeda4e618c0c325e43e82a1d3ac146fbe419b446.tar.xz
Limit the number of prev_events of new events
Diffstat (limited to '')
-rw-r--r--synapse/handlers/message.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index abfa8c65a4..3eca46df86 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -34,6 +34,7 @@ from ._base import BaseHandler
 from canonicaljson import encode_canonical_json
 
 import logging
+import random
 
 logger = logging.getLogger(__name__)
 
@@ -415,6 +416,18 @@ class MessageHandler(BaseHandler):
                 builder.room_id,
             )
 
+            # We want to limit the max number of prev events we point to in our
+            # new event
+            if len(latest_ret) > 10:
+                # Sort by reverse depth, so we point to the most recent.
+                latest_ret.sort(key=lambda a: -a[2])
+                new_latest_ret = latest_ret[:5]
+
+                # We also randomly point to some of the older events, to make
+                # sure that we don't completely ignore the older events.
+                new_latest_ret.extend(random.sample(latest_ret, 5))
+                latest_ret = new_latest_ret
+
             if latest_ret:
                 depth = max([d for _, _, d in latest_ret]) + 1
             else: