Merge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes

This commit is contained in:
Erik Johnston 2017-04-26 14:03:15 +01:00
commit 05e62e0478
7 changed files with 67 additions and 16 deletions

View File

@ -245,6 +245,25 @@ Setting up a TURN server
For reliable VoIP calls to be routed via this homeserver, you MUST configure For reliable VoIP calls to be routed via this homeserver, you MUST configure
a TURN server. See `<docs/turn-howto.rst>`_ for details. a TURN server. See `<docs/turn-howto.rst>`_ for details.
IPv6
----
As of Synapse 0.19 we finally support IPv6, many thanks to @kyrias and @glyph
for providing PR #1696.
However, for federation to work on hosts with IPv6 DNS servers you **must**
be running Twisted 17.1.0 or later - see https://github.com/matrix-org/synapse/issues/1002
for details. We can't make Synapse depend on Twisted 17.1 by default
yet as it will break most older distributions (see https://github.com/matrix-org/synapse/pull/1909)
so if you are using operating system dependencies you'll have to install your
own Twisted 17.1 package via pip or backports etc.
If you're running in a virtualenv then pip should have installed the newest
Twisted automatically, but if your virtualenv is old you will need to manually
upgrade to a newer Twisted dependency via:
pip install Twisted>=17.1.0
Running Synapse Running Synapse
=============== ===============

View File

@ -21,13 +21,12 @@ How to monitor Synapse metrics using Prometheus
3. Add a prometheus target for synapse. 3. Add a prometheus target for synapse.
It needs to set the ``metrics_path`` to a non-default value:: It needs to set the ``metrics_path`` to a non-default value (under ``scrape_configs``)::
- job_name: "synapse" - job_name: "synapse"
metrics_path: "/_synapse/metrics" metrics_path: "/_synapse/metrics"
static_configs: static_configs:
- targets: - targets: ["my.server.here:9092"]
"my.server.here:9092"
If your prometheus is older than 1.5.2, you will need to replace If your prometheus is older than 1.5.2, you will need to replace
``static_configs`` in the above with ``target_groups``. ``static_configs`` in the above with ``target_groups``.

View File

@ -87,7 +87,11 @@ class BulkPushRuleEvaluator:
condition_cache = {} condition_cache = {}
for uid, rules in self.rules_by_user.items(): for uid, rules in self.rules_by_user.items():
display_name = room_members.get(uid, {}).get("display_name", None) display_name = None
profile_info = room_members.get(uid)
if profile_info:
display_name = profile_info.display_name
if not display_name: if not display_name:
# Handle the case where we are pushing a membership event to # Handle the case where we are pushing a membership event to
# that user, as they might not be already joined. # that user, as they might not be already joined.

View File

@ -406,7 +406,13 @@ class JoinedRoomMemberListRestServlet(ClientV1RestServlet):
users_with_profile = yield self.state.get_current_user_in_room(room_id) users_with_profile = yield self.state.get_current_user_in_room(room_id)
defer.returnValue((200, { defer.returnValue((200, {
"joined": users_with_profile "joined": {
user_id: {
"avatar_url": profile.avatar_url,
"display_name": profile.display_name,
}
for user_id, profile in users_with_profile.iteritems()
}
})) }))

View File

@ -19,6 +19,7 @@ from collections import namedtuple
from ._base import SQLBaseStore from ._base import SQLBaseStore
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks from synapse.util.caches.descriptors import cached, cachedInlineCallbacks
from synapse.util.stringutils import to_ascii
from synapse.api.constants import Membership, EventTypes from synapse.api.constants import Membership, EventTypes
from synapse.types import get_domain_from_id from synapse.types import get_domain_from_id
@ -35,6 +36,13 @@ RoomsForUser = namedtuple(
) )
# We store this using a namedtuple so that we save about 3x space over using a
# dict.
ProfileInfo = namedtuple(
"ProfileInfo", ("avatar_url", "display_name")
)
_MEMBERSHIP_PROFILE_UPDATE_NAME = "room_membership_profile_update" _MEMBERSHIP_PROFILE_UPDATE_NAME = "room_membership_profile_update"
@ -422,20 +430,20 @@ class RoomMemberStore(SQLBaseStore):
) )
users_in_room = { users_in_room = {
row["user_id"]: { to_ascii(row["user_id"]): ProfileInfo(
"display_name": row["display_name"], avatar_url=to_ascii(row["avatar_url"]),
"avatar_url": row["avatar_url"], display_name=to_ascii(row["display_name"]),
} )
for row in rows for row in rows
} }
if event is not None and event.type == EventTypes.Member: if event is not None and event.type == EventTypes.Member:
if event.membership == Membership.JOIN: if event.membership == Membership.JOIN:
if event.event_id in member_event_ids: if event.event_id in member_event_ids:
users_in_room[event.state_key] = { users_in_room[to_ascii(event.state_key)] = ProfileInfo(
"display_name": event.content.get("displayname", None), display_name=to_ascii(event.content.get("displayname", None)),
"avatar_url": event.content.get("avatar_url", None), avatar_url=to_ascii(event.content.get("avatar_url", None)),
} )
defer.returnValue(users_in_room) defer.returnValue(users_in_room)

View File

@ -16,6 +16,7 @@
from ._base import SQLBaseStore from ._base import SQLBaseStore
from synapse.util.caches.descriptors import cached, cachedList from synapse.util.caches.descriptors import cached, cachedList
from synapse.util.caches import intern_string from synapse.util.caches import intern_string
from synapse.util.stringutils import to_ascii
from synapse.storage.engines import PostgresEngine from synapse.storage.engines import PostgresEngine
from twisted.internet import defer from twisted.internet import defer
@ -89,7 +90,7 @@ class StateStore(SQLBaseStore):
) )
return { return {
(r[0], r[1]): r[2] for r in txn (intern_string(r[0]), intern_string(r[1])): to_ascii(r[2]) for r in txn
} }
return self.runInteraction( return self.runInteraction(
@ -507,7 +508,7 @@ class StateStore(SQLBaseStore):
state_map = yield self.get_state_ids_for_events([event_id], types) state_map = yield self.get_state_ids_for_events([event_id], types)
defer.returnValue(state_map[event_id]) defer.returnValue(state_map[event_id])
@cached(num_args=2, max_entries=100000) @cached(num_args=2, max_entries=50000)
def _get_state_group_for_event(self, room_id, event_id): def _get_state_group_for_event(self, room_id, event_id):
return self._simple_select_one_onecol( return self._simple_select_one_onecol(
table="event_to_state_groups", table="event_to_state_groups",
@ -655,7 +656,7 @@ class StateStore(SQLBaseStore):
state_dict = results[group] state_dict = results[group]
state_dict.update( state_dict.update(
((intern_string(k[0]), intern_string(k[1])), v) ((intern_string(k[0]), intern_string(k[1])), to_ascii(v))
for k, v in group_state_dict.iteritems() for k, v in group_state_dict.iteritems()
) )

View File

@ -40,3 +40,17 @@ def is_ascii(s):
return False return False
else: else:
return True return True
def to_ascii(s):
"""Converts a string to ascii if it is ascii, otherwise leave it alone.
If given None then will return None.
"""
if s is None:
return None
try:
return s.encode("ascii")
except UnicodeEncodeError:
return s