Optimize get_un_partial_stated_rooms_between

This commit is contained in:
Mathieu Velten 2023-01-18 12:38:48 +01:00
parent fbfafca0ab
commit 6472178a41
2 changed files with 9 additions and 3 deletions

View file

@ -1831,6 +1831,7 @@ class SyncHandler:
await self.store.get_un_partial_stated_rooms_between(
un_partial_stated_rooms_since,
sync_result_builder.now_token.un_partial_stated_rooms_key,
sync_result_builder.joined_room_ids,
)
)

View file

@ -1287,7 +1287,7 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
return self._un_partial_stated_rooms_stream_id_gen.get_current_token()
async def get_un_partial_stated_rooms_between(
self, last_id: int, current_id: int
self, last_id: int, current_id: int, room_ids: Collection[str]
) -> Set[str]:
"""Get all rooms that got un partial stated between `last_id` exclusive and
`current_id` inclusive.
@ -1304,9 +1304,14 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
) -> Set[str]:
sql = """
SELECT DISTINCT room_id FROM un_partial_stated_room_stream
WHERE ? < stream_id AND stream_id <= ?
WHERE ? < stream_id AND stream_id <= ? AND
"""
txn.execute(sql, (last_id, current_id))
clause, args = make_in_list_sql_clause(
self.database_engine, "room_id", room_ids
)
txn.execute(sql + clause, [last_id, current_id] + list(args))
return {r[0] for r in txn}