mirror of
https://github.com/element-hq/synapse
synced 2024-08-20 22:30:21 +00:00
Batch look-ups to see if rooms are partial stated.
This commit is contained in:
parent
f51035bc87
commit
e8a96bcc39
3 changed files with 28 additions and 8 deletions
1
changelog.d/14917.misc
Normal file
1
changelog.d/14917.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Improve performance of looking up partial-state status.
|
|
@ -1383,9 +1383,9 @@ class SyncHandler:
|
|||
if not sync_config.filter_collection.lazy_load_members():
|
||||
# Non-lazy syncs should never include partially stated rooms.
|
||||
# Exclude all partially stated rooms from this sync.
|
||||
for room_id in mutable_joined_room_ids:
|
||||
if await self.store.is_partial_state_room(room_id):
|
||||
mutable_rooms_to_exclude.add(room_id)
|
||||
results = await self.store.is_partial_state_rooms(mutable_joined_room_ids)
|
||||
for room_id, result in results.items():
|
||||
mutable_rooms_to_exclude.add(room_id)
|
||||
|
||||
# Incremental eager syncs should additionally include rooms that
|
||||
# - we are joined to
|
||||
|
@ -1401,9 +1401,9 @@ class SyncHandler:
|
|||
mutable_joined_room_ids,
|
||||
)
|
||||
)
|
||||
for room_id in un_partial_stated_rooms:
|
||||
if not await self.store.is_partial_state_room(room_id):
|
||||
forced_newly_joined_room_ids.add(room_id)
|
||||
results = await self.store.is_partial_state_rooms(un_partial_stated_rooms)
|
||||
for room_id, result in results.items():
|
||||
forced_newly_joined_room_ids.add(room_id)
|
||||
|
||||
# Now we have our list of joined room IDs, exclude as configured and freeze
|
||||
joined_room_ids = frozenset(
|
||||
|
|
|
@ -60,9 +60,9 @@ from synapse.storage.util.id_generators import (
|
|||
MultiWriterIdGenerator,
|
||||
StreamIdGenerator,
|
||||
)
|
||||
from synapse.types import JsonDict, RetentionPolicy, ThirdPartyInstanceID
|
||||
from synapse.types import JsonDict, RetentionPolicy, StrCollection, ThirdPartyInstanceID
|
||||
from synapse.util import json_encoder
|
||||
from synapse.util.caches.descriptors import cached
|
||||
from synapse.util.caches.descriptors import cached, cachedList
|
||||
from synapse.util.stringutils import MXC_REGEX
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -1274,6 +1274,25 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
|
|||
|
||||
return entry is not None
|
||||
|
||||
@cachedList(cached_method_name="is_partial_State_room", list_name="room_ids")
|
||||
async def is_partial_state_rooms(self, room_ids: StrCollection) -> Mapping[str, bool]:
|
||||
"""Checks if this room has partial state.
|
||||
|
||||
Returns true if this is a "partial-state" room, which means that the state
|
||||
at events in the room, and `current_state_events`, may not yet be
|
||||
complete.
|
||||
"""
|
||||
|
||||
entries = set(await self.db_pool.simple_select_many_batch(
|
||||
table="partial_state_rooms",
|
||||
column="room_id",
|
||||
iterable=room_ids,
|
||||
retcols=("room_id",),
|
||||
desc="is_partial_state_room",
|
||||
))
|
||||
|
||||
return {room_id: room_id in entries for room_id in room_ids}
|
||||
|
||||
async def get_join_event_id_and_device_lists_stream_id_for_partial_state(
|
||||
self, room_id: str
|
||||
) -> Tuple[str, int]:
|
||||
|
|
Loading…
Reference in a new issue