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

Commit

Permalink
Merge branch 'develop' into matrix-org-hotfixes
Browse files Browse the repository at this point in the history
* develop:
  Don't unnecessarily start bg process in replication sending loop. (#8670)
  Don't unnecessarily start bg process while handling typing. (#8668)
  • Loading branch information
anoadragon453 committed Oct 28, 2020
2 parents d60af93 + 4215a3a commit 172ddb3
Show file tree
Hide file tree
Showing 4 changed files with 25 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.
1 change: 1 addition & 0 deletions changelog.d/8670.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
10 changes: 10 additions & 0 deletions synapse/replication/tcp/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ def on_notifier_poke(self):
stream.discard_updates_and_advance()
return

# We check up front to see if anything has actually changed, as we get
# poked because of changes that happened on other instances.
if all(
stream.last_token == stream.current_token(self._instance_name)
for stream in self.streams
):
return

# If there are updates then we need to set this even if we're already
# looping, as the loop needs to know that he might need to loop again.
self.pending_updates = True

if self.is_looping:
Expand Down

0 comments on commit 172ddb3

Please sign in to comment.