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

Commit

Permalink
Don't unnecessarily start bg process while handling typing. (#8668)
Browse files Browse the repository at this point in the history
There's no point starting a background process when all its going to do is bail if federation isn't enabled.
  • Loading branch information
erikjohnston authored Oct 27, 2020
1 parent 9b7c282 commit 0c7f9cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/8668.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce number of OpenTracing spans started.
21 changes: 13 additions & 8 deletions synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,25 @@ def process_replication_rows(
now_typing = set(row.user_ids)
self._room_typing[row.room_id] = row.user_ids

run_as_background_process(
"_handle_change_in_typing",
self._handle_change_in_typing,
row.room_id,
prev_typing,
now_typing,
)
if self.federation:
run_as_background_process(
"_send_changes_in_typing_to_remotes",
self._send_changes_in_typing_to_remotes,
row.room_id,
prev_typing,
now_typing,
)

async def _handle_change_in_typing(
async def _send_changes_in_typing_to_remotes(
self, room_id: str, prev_typing: Set[str], now_typing: Set[str]
):
"""Process a change in typing of a room from replication, sending EDUs
for any local users.
"""

if not self.federation:
return

for user_id in now_typing - prev_typing:
if self.is_mine_id(user_id):
await self._push_remote(RoomMember(room_id, user_id), True)
Expand Down

0 comments on commit 0c7f9cb

Please sign in to comment.