mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-29 21:16:10 -05:00
Make get_joined_users faster
This commit is contained in:
parent
3033261891
commit
7ebf518c02
@ -417,25 +417,47 @@ class RoomMemberStore(SQLBaseStore):
|
|||||||
if key[0] == EventTypes.Member
|
if key[0] == EventTypes.Member
|
||||||
]
|
]
|
||||||
|
|
||||||
rows = yield self._simple_select_many_batch(
|
event_map = self._get_events_from_cache(
|
||||||
table="room_memberships",
|
member_event_ids,
|
||||||
column="event_id",
|
allow_rejected=False,
|
||||||
iterable=member_event_ids,
|
|
||||||
retcols=['user_id', 'display_name', 'avatar_url'],
|
|
||||||
keyvalues={
|
|
||||||
"membership": Membership.JOIN,
|
|
||||||
},
|
|
||||||
batch_size=500,
|
|
||||||
desc="_get_joined_users_from_context",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
users_in_room = {
|
missing_member_event_ids = []
|
||||||
to_ascii(row["user_id"]): ProfileInfo(
|
users_in_room = {}
|
||||||
avatar_url=to_ascii(row["avatar_url"]),
|
for event_id, ev_entry in event_map.iteritems():
|
||||||
display_name=to_ascii(row["display_name"]),
|
if event_id:
|
||||||
|
if ev_entry.event.membership == Membership.JOIN:
|
||||||
|
users_in_room[to_ascii(ev_entry.event.state_key)] = ProfileInfo(
|
||||||
|
display_name=to_ascii(
|
||||||
|
ev_entry.event.content.get("displayname", None)
|
||||||
|
),
|
||||||
|
avatar_url=to_ascii(
|
||||||
|
ev_entry.event.content.get("avatar_url", None)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
missing_member_event_ids.append(event_id)
|
||||||
|
|
||||||
|
if missing_member_event_ids:
|
||||||
|
rows = yield self._simple_select_many_batch(
|
||||||
|
table="room_memberships",
|
||||||
|
column="event_id",
|
||||||
|
iterable=member_event_ids,
|
||||||
|
retcols=('user_id', 'display_name', 'avatar_url',),
|
||||||
|
keyvalues={
|
||||||
|
"membership": Membership.JOIN,
|
||||||
|
},
|
||||||
|
batch_size=500,
|
||||||
|
desc="_get_joined_users_from_context",
|
||||||
)
|
)
|
||||||
for row in rows
|
|
||||||
}
|
users_in_room.update({
|
||||||
|
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 is not None and event.type == EventTypes.Member:
|
||||||
if event.membership == Membership.JOIN:
|
if event.membership == Membership.JOIN:
|
||||||
|
Loading…
Reference in New Issue
Block a user