diff options
author | Erik Johnston <erik@matrix.org> | 2017-04-25 14:38:51 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-04-25 14:38:51 +0100 |
commit | d9aa645f86db733bb0419b5f5428ba9a9c799735 (patch) | |
tree | 3bd3cc61f7656609e6642351014401b20f2882c8 /synapse/util | |
parent | Reduce _get_state_group_for_event cache size (diff) | |
download | synapse-d9aa645f86db733bb0419b5f5428ba9a9c799735.tar.xz |
Reduce size of joined_user cache
The _get_joined_users_from_context cache stores a mapping from user_id to avatar_url and display_name. Instead of storing those in a dict, store them in a namedtuple as that uses much less memory. We also try converting the string to ascii to further reduce the size.
Diffstat (limited to '')
-rw-r--r-- | synapse/util/stringutils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py index a100f151d4..95a6168e16 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py @@ -40,3 +40,17 @@ def is_ascii(s): return False else: 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 |