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

Improve appservice handler to send only the most recent ephemeral events when no stream_id is stored. #8744

Merged
merged 8 commits into from
Nov 18, 2020
Merged
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/8744.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where appservices may be sent an excessive amount of read receipts and presence. Broke in v1.22.0.
2 changes: 1 addition & 1 deletion synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def _notify_interested_services_ephemeral(
new_token: Optional[int],
users: Collection[Union[str, UserID]],
):
logger.info("Checking interested services for %s" % (stream_key))
logger.debug("Checking interested services for %s" % (stream_key))
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved
with Measure(self.clock, "notify_interested_services_ephemeral"):
for service in services:
# Only handle typing if we have the latest token
Expand Down
3 changes: 2 additions & 1 deletion synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ async def get_new_events_as(
if from_key == to_key:
return [], to_key

# We first need to fetch all new receipts
# Fetch all read receipts for all rooms, up to a limit of 100. This is ordered
# by most recent.
rooms_to_events = await self.store.get_linearized_receipts_for_all_rooms(
from_key=from_key, to_key=to_key
)
Expand Down
7 changes: 6 additions & 1 deletion synapse/storage/databases/main/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ def f(txn):
async def get_linearized_receipts_for_all_rooms(
self, to_key: int, from_key: Optional[int] = None
) -> Dict[str, JsonDict]:
"""Get receipts for all rooms between two stream_ids.
"""Get receipts for all rooms between two stream_ids, up
to a limit of the latest 100 read receipts.

Args:
to_key: Max stream id to fetch receipts upto.
Expand All @@ -294,12 +295,16 @@ def f(txn):
sql = """
SELECT * FROM receipts_linearized WHERE
stream_id > ? AND stream_id <= ?
ORDER BY stream_id DESC
LIMIT 100
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved
"""
txn.execute(sql, [from_key, to_key])
else:
sql = """
SELECT * FROM receipts_linearized WHERE
stream_id <= ?
ORDER BY stream_id DESC
LIMIT 100
"""

txn.execute(sql, [to_key])
Expand Down