Improve appservice handler to send only the most recent read receipts when no stream_id is stored. (#8744)

* Make this line debug (it's noisy)

* Don't include from_key for presence if we are at 0

* Limit read receipts for all rooms to 100

* changelog.d/8744.bugfix

* Allow from_key to be None

* Update 8744.bugfix

* The from_key is superflous

* Update comment
This commit is contained in:
Will Hunt 2020-11-18 18:54:09 +00:00 committed by GitHub
parent 03e392f787
commit 51338491c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 3 deletions

1
changelog.d/8744.bugfix Normal file
View file

@ -0,0 +1 @@
Fix a bug where appservices may be sent an excessive amount of read receipts and presence. Broke in v1.22.0.

View file

@ -226,7 +226,7 @@ class ApplicationServicesHandler:
new_token: Optional[int], new_token: Optional[int],
users: Collection[Union[str, UserID]], users: Collection[Union[str, UserID]],
): ):
logger.info("Checking interested services for %s" % (stream_key)) logger.debug("Checking interested services for %s" % (stream_key))
with Measure(self.clock, "notify_interested_services_ephemeral"): with Measure(self.clock, "notify_interested_services_ephemeral"):
for service in services: for service in services:
# Only handle typing if we have the latest token # Only handle typing if we have the latest token

View file

@ -158,7 +158,8 @@ class ReceiptEventSource:
if from_key == to_key: if from_key == to_key:
return [], 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( rooms_to_events = await self.store.get_linearized_receipts_for_all_rooms(
from_key=from_key, to_key=to_key from_key=from_key, to_key=to_key
) )

View file

@ -278,7 +278,8 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta):
async def get_linearized_receipts_for_all_rooms( async def get_linearized_receipts_for_all_rooms(
self, to_key: int, from_key: Optional[int] = None self, to_key: int, from_key: Optional[int] = None
) -> Dict[str, JsonDict]: ) -> 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: Args:
to_key: Max stream id to fetch receipts upto. to_key: Max stream id to fetch receipts upto.
@ -294,12 +295,16 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta):
sql = """ sql = """
SELECT * FROM receipts_linearized WHERE SELECT * FROM receipts_linearized WHERE
stream_id > ? AND stream_id <= ? stream_id > ? AND stream_id <= ?
ORDER BY stream_id DESC
LIMIT 100
""" """
txn.execute(sql, [from_key, to_key]) txn.execute(sql, [from_key, to_key])
else: else:
sql = """ sql = """
SELECT * FROM receipts_linearized WHERE SELECT * FROM receipts_linearized WHERE
stream_id <= ? stream_id <= ?
ORDER BY stream_id DESC
LIMIT 100
""" """
txn.execute(sql, [to_key]) txn.execute(sql, [to_key])