Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Always calculate heroes for rooms without avatars #3898

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3898.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Always calculate heroes for rooms without avatars
40 changes: 24 additions & 16 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,13 @@ def compute_summary(self, room_id, sync_config, batch, state, now_token):
state_filter=StateFilter.from_types([
(EventTypes.Name, ''),
(EventTypes.CanonicalAlias, ''),
(EventTypes.RoomAvatar, ''),
]),
)

# this is heavily cached, thus: fast.
details = yield self.store.get_room_summary(room_id)

name_id = state_ids.get((EventTypes.Name, ''))
canonical_alias_id = state_ids.get((EventTypes.CanonicalAlias, ''))

summary = {}
empty_ms = MemberSummary([], 0)

Expand All @@ -579,21 +577,31 @@ def compute_summary(self, room_id, sync_config, batch, state, now_token):
details.get(Membership.INVITE, empty_ms).count
)

# if the room has a name or canonical_alias set, we can skip
# calculating heroes. we assume that if the event has contents, it'll
# if the room has no avatar, we need to calculate heroes.
# otherwise, if the room has a name or canonical_alias set, we can skip
# calculating heroes.
# we assume that if the event has contents, it'll
# be a valid name or canonical_alias - i.e. we're checking that they
# haven't been "deleted" by blatting {} over the top.
if name_id:
name = yield self.store.get_event(name_id, allow_none=True)
if name and name.content:
defer.returnValue(summary)

if canonical_alias_id:
canonical_alias = yield self.store.get_event(
canonical_alias_id, allow_none=True,
)
if canonical_alias and canonical_alias.content:
defer.returnValue(summary)
room_avatar_id = state_ids.get((EventTypes.RoomAvatar, ''))
if room_avatar_id:
room_avatar = yield self.store.get_event(room_avatar_id, allow_none=True)
if room_avatar and room_avatar.content:
# we have a room avatar; check to see if we can skip heroes
# because the room has an explicit name or canonical alias:
name_id = state_ids.get((EventTypes.Name, ''))
if name_id:
name = yield self.store.get_event(name_id, allow_none=True)
if name and name.content:
defer.returnValue(summary)

canonical_alias_id = state_ids.get((EventTypes.CanonicalAlias, ''))
if canonical_alias_id:
canonical_alias = yield self.store.get_event(
canonical_alias_id, allow_none=Tue,
)
if canonical_alias and canonical_alias.content:
defer.returnValue(summary)

joined_user_ids = [
r[0] for r in details.get(Membership.JOIN, empty_ms).members
Expand Down