summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-11-08 11:20:26 +0000
committerErik Johnston <erik@matrix.org>2016-11-08 11:20:26 +0000
commita4632783fba26aaaedd0b9777877cb2ec8b48752 (patch)
tree51fe16103e36d790614ac5c0ade6978234c1a955
parentLimit the number of prev_events of new events (diff)
downloadsynapse-a4632783fba26aaaedd0b9777877cb2ec8b48752.tar.xz
Sample correctly
-rw-r--r--synapse/handlers/message.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 3eca46df86..81df45177a 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -425,7 +425,9 @@ class MessageHandler(BaseHandler):
 
                 # 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))
+                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: