summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-11-22 10:25:23 +0000
committerErik Johnston <erik@matrix.org>2016-11-22 10:25:23 +0000
commitf9834a3d1a25d0a715718a53e10752399985e3aa (patch)
tree3d868eafb43d9646b15cd1aaee0f4093db802fd3 /synapse/handlers
parentMerge branch 'erikj/ldap3_auth' (diff)
parentBump changelog (diff)
downloadsynapse-f9834a3d1a25d0a715718a53e10752399985e3aa.tar.xz
Merge branch 'release-v0.18.4' of github.com:matrix-org/synapse v0.18.4
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/auth.py2
-rw-r--r--synapse/handlers/message.py15
2 files changed, 16 insertions, 1 deletions
diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py
index 3635521230..3851b35889 100644
--- a/synapse/handlers/auth.py
+++ b/synapse/handlers/auth.py
@@ -653,7 +653,7 @@ class AuthHandler(BaseHandler):
         Returns:
             Hashed password (str).
         """
-        return bcrypt.hashpw(password + self.hs.config.password_pepper,
+        return bcrypt.hashpw(password.encode('utf8') + self.hs.config.password_pepper,
                              bcrypt.gensalt(self.bcrypt_rounds))
 
     def validate_hash(self, password, stored_hash):
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: