mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 12:46:01 -04:00
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.
This commit is contained in:
parent
22f3d3ae76
commit
d9aa645f86
4 changed files with 40 additions and 11 deletions
|
@ -19,6 +19,7 @@ from collections import namedtuple
|
|||
|
||||
from ._base import SQLBaseStore
|
||||
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks
|
||||
from synapse.util.stringutils import to_ascii
|
||||
|
||||
from synapse.api.constants import Membership, EventTypes
|
||||
from synapse.types import get_domain_from_id
|
||||
|
@ -35,6 +36,11 @@ RoomsForUser = namedtuple(
|
|||
)
|
||||
|
||||
|
||||
ProfileInfo = namedtuple(
|
||||
"ProfileInfo", ("avatar_url", "display_name")
|
||||
)
|
||||
|
||||
|
||||
_MEMBERSHIP_PROFILE_UPDATE_NAME = "room_membership_profile_update"
|
||||
|
||||
|
||||
|
@ -422,20 +428,20 @@ class RoomMemberStore(SQLBaseStore):
|
|||
)
|
||||
|
||||
users_in_room = {
|
||||
row["user_id"]: {
|
||||
"display_name": row["display_name"],
|
||||
"avatar_url": row["avatar_url"],
|
||||
}
|
||||
to_ascii(row["user_id"]): ProfileInfo(
|
||||
avatar_url=to_ascii(row["avatar_url"]),
|
||||
display_name=to_ascii(row["display_name"]),
|
||||
)
|
||||
for row in rows
|
||||
}
|
||||
|
||||
if event is not None and event.type == EventTypes.Member:
|
||||
if event.membership == Membership.JOIN:
|
||||
if event.event_id in member_event_ids:
|
||||
users_in_room[event.state_key] = {
|
||||
"display_name": event.content.get("displayname", None),
|
||||
"avatar_url": event.content.get("avatar_url", None),
|
||||
}
|
||||
users_in_room[to_ascii(event.state_key)] = ProfileInfo(
|
||||
display_name=to_ascii(event.content.get("displayname", None)),
|
||||
avatar_url=to_ascii(event.content.get("avatar_url", None)),
|
||||
)
|
||||
|
||||
defer.returnValue(users_in_room)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue