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

Commit

Permalink
Merge pull request #1615 from matrix-org/erikj/limit_prev_events
Browse files Browse the repository at this point in the history
Limit the number of prev_events of new events
  • Loading branch information
erikjohnston authored Nov 8, 2016
2 parents 34449cf + a463278 commit 17e0a58
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from canonicaljson import encode_canonical_json

import logging
import random

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -415,6 +416,20 @@ def _create_new_client_event(self, builder, prev_event_ids=None):
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:
Expand Down

0 comments on commit 17e0a58

Please sign in to comment.