diff options
author | Erik Johnston <erikj@jki.re> | 2016-11-08 12:06:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-08 12:06:15 +0000 |
commit | 17e0a58020abac5bf3d68d06443b0aba326bc190 (patch) | |
tree | 6b58a3f393d8223e4cdb9865c5ef1e0775df461e /synapse/handlers/message.py | |
parent | Merge pull request #1616 from matrix-org/erikj/worker_frozen_dict (diff) | |
parent | Sample correctly (diff) | |
download | synapse-17e0a58020abac5bf3d68d06443b0aba326bc190.tar.xz |
Merge pull request #1615 from matrix-org/erikj/limit_prev_events
Limit the number of prev_events of new events
Diffstat (limited to 'synapse/handlers/message.py')
-rw-r--r-- | synapse/handlers/message.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index abfa8c65a4..81df45177a 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,20 @@ 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. + if latest_ret[5:]: + sample_size = min(5, len(latest_ret[5:])) + new_latest_ret.extend(random.sample(latest_ret[5:], sample_size)) + latest_ret = new_latest_ret + if latest_ret: depth = max([d for _, _, d in latest_ret]) + 1 else: |