mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-17 21:20:12 -04:00
Merge remote-tracking branch 'upstream/release-v1.69'
This commit is contained in:
commit
4b94513ae4
191 changed files with 10356 additions and 2903 deletions
|
@ -423,16 +423,18 @@ class EventsPersistenceStorageController:
|
|||
for d in ret_vals:
|
||||
replaced_events.update(d)
|
||||
|
||||
events = []
|
||||
persisted_events = []
|
||||
for event, _ in events_and_contexts:
|
||||
existing_event_id = replaced_events.get(event.event_id)
|
||||
if existing_event_id:
|
||||
events.append(await self.main_store.get_event(existing_event_id))
|
||||
persisted_events.append(
|
||||
await self.main_store.get_event(existing_event_id)
|
||||
)
|
||||
else:
|
||||
events.append(event)
|
||||
persisted_events.append(event)
|
||||
|
||||
return (
|
||||
events,
|
||||
persisted_events,
|
||||
self.main_store.get_room_max_token(),
|
||||
)
|
||||
|
||||
|
@ -598,11 +600,6 @@ class EventsPersistenceStorageController:
|
|||
# room
|
||||
state_delta_for_room: Dict[str, DeltaState] = {}
|
||||
|
||||
# Set of remote users which were in rooms the server has left or who may
|
||||
# have left rooms the server is in. We should check if we still share any
|
||||
# rooms and if not we mark their device lists as stale.
|
||||
potentially_left_users: Set[str] = set()
|
||||
|
||||
if not backfilled:
|
||||
with Measure(self._clock, "_calculate_state_and_extrem"):
|
||||
# Work out the new "current state" for each room.
|
||||
|
@ -716,8 +713,6 @@ class EventsPersistenceStorageController:
|
|||
room_id,
|
||||
ev_ctx_rm,
|
||||
delta,
|
||||
current_state,
|
||||
potentially_left_users,
|
||||
)
|
||||
if not is_still_joined:
|
||||
logger.info("Server no longer in room %s", room_id)
|
||||
|
@ -725,20 +720,6 @@ class EventsPersistenceStorageController:
|
|||
current_state = {}
|
||||
delta.no_longer_in_room = True
|
||||
|
||||
# Add all remote users that might have left rooms.
|
||||
potentially_left_users.update(
|
||||
user_id
|
||||
for event_type, user_id in delta.to_delete
|
||||
if event_type == EventTypes.Member
|
||||
and not self.is_mine_id(user_id)
|
||||
)
|
||||
potentially_left_users.update(
|
||||
user_id
|
||||
for event_type, user_id in delta.to_insert.keys()
|
||||
if event_type == EventTypes.Member
|
||||
and not self.is_mine_id(user_id)
|
||||
)
|
||||
|
||||
state_delta_for_room[room_id] = delta
|
||||
|
||||
await self.persist_events_store._persist_events_and_state_updates(
|
||||
|
@ -749,8 +730,6 @@ class EventsPersistenceStorageController:
|
|||
inhibit_local_membership_updates=backfilled,
|
||||
)
|
||||
|
||||
await self._handle_potentially_left_users(potentially_left_users)
|
||||
|
||||
return replaced_events
|
||||
|
||||
async def _calculate_new_extremities(
|
||||
|
@ -1126,8 +1105,6 @@ class EventsPersistenceStorageController:
|
|||
room_id: str,
|
||||
ev_ctx_rm: List[Tuple[EventBase, EventContext]],
|
||||
delta: DeltaState,
|
||||
current_state: Optional[StateMap[str]],
|
||||
potentially_left_users: Set[str],
|
||||
) -> bool:
|
||||
"""Check if the server will still be joined after the given events have
|
||||
been persised.
|
||||
|
@ -1137,11 +1114,6 @@ class EventsPersistenceStorageController:
|
|||
ev_ctx_rm
|
||||
delta: The delta of current state between what is in the database
|
||||
and what the new current state will be.
|
||||
current_state: The new current state if it already been calculated,
|
||||
otherwise None.
|
||||
potentially_left_users: If the server has left the room, then joined
|
||||
remote users will be added to this set to indicate that the
|
||||
server may no longer be sharing a room with them.
|
||||
"""
|
||||
|
||||
if not any(
|
||||
|
@ -1195,45 +1167,4 @@ class EventsPersistenceStorageController:
|
|||
):
|
||||
return True
|
||||
|
||||
# The server will leave the room, so we go and find out which remote
|
||||
# users will still be joined when we leave.
|
||||
if current_state is None:
|
||||
current_state = await self.main_store.get_partial_current_state_ids(room_id)
|
||||
current_state = dict(current_state)
|
||||
for key in delta.to_delete:
|
||||
current_state.pop(key, None)
|
||||
|
||||
current_state.update(delta.to_insert)
|
||||
|
||||
remote_event_ids = [
|
||||
event_id
|
||||
for (
|
||||
typ,
|
||||
state_key,
|
||||
), event_id in current_state.items()
|
||||
if typ == EventTypes.Member and not self.is_mine_id(state_key)
|
||||
]
|
||||
members = await self.main_store.get_membership_from_event_ids(remote_event_ids)
|
||||
potentially_left_users.update(
|
||||
member.user_id
|
||||
for member in members.values()
|
||||
if member and member.membership == Membership.JOIN
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
async def _handle_potentially_left_users(self, user_ids: Set[str]) -> None:
|
||||
"""Given a set of remote users check if the server still shares a room with
|
||||
them. If not then mark those users' device cache as stale.
|
||||
"""
|
||||
|
||||
if not user_ids:
|
||||
return
|
||||
|
||||
joined_users = await self.main_store.get_users_server_still_shares_room_with(
|
||||
user_ids
|
||||
)
|
||||
left_users = user_ids - joined_users
|
||||
|
||||
for user_id in left_users:
|
||||
await self.main_store.mark_remote_user_device_list_as_unsubscribed(user_id)
|
||||
|
|
|
@ -23,6 +23,7 @@ from typing import (
|
|||
List,
|
||||
Mapping,
|
||||
Optional,
|
||||
Set,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
|
@ -406,6 +407,7 @@ class StateStorageController:
|
|||
self,
|
||||
room_id: str,
|
||||
state_filter: Optional[StateFilter] = None,
|
||||
await_full_state: bool = True,
|
||||
on_invalidate: Optional[Callable[[], None]] = None,
|
||||
) -> StateMap[str]:
|
||||
"""Get the current state event ids for a room based on the
|
||||
|
@ -418,13 +420,17 @@ class StateStorageController:
|
|||
room_id: The room to get the state IDs of. state_filter: The state
|
||||
filter used to fetch state from the
|
||||
database.
|
||||
await_full_state: if true, will block if we do not yet have complete
|
||||
state for the room.
|
||||
on_invalidate: Callback for when the `get_current_state_ids` cache
|
||||
for the room gets invalidated.
|
||||
|
||||
Returns:
|
||||
The current state of the room.
|
||||
"""
|
||||
if not state_filter or state_filter.must_await_full_state(self._is_mine_id):
|
||||
if await_full_state and (
|
||||
not state_filter or state_filter.must_await_full_state(self._is_mine_id)
|
||||
):
|
||||
await self._partial_state_room_tracker.await_full_state(room_id)
|
||||
|
||||
if state_filter and not state_filter.is_full():
|
||||
|
@ -523,13 +529,60 @@ class StateStorageController:
|
|||
)
|
||||
return state_map.get(key)
|
||||
|
||||
async def get_current_hosts_in_room(self, room_id: str) -> List[str]:
|
||||
"""Get current hosts in room based on current state."""
|
||||
async def get_current_hosts_in_room(self, room_id: str) -> Set[str]:
|
||||
"""Get current hosts in room based on current state.
|
||||
|
||||
Blocks until we have full state for the given room. This only happens for rooms
|
||||
with partial state.
|
||||
"""
|
||||
|
||||
await self._partial_state_room_tracker.await_full_state(room_id)
|
||||
|
||||
return await self.stores.main.get_current_hosts_in_room(room_id)
|
||||
|
||||
async def get_current_hosts_in_room_ordered(self, room_id: str) -> List[str]:
|
||||
"""Get current hosts in room based on current state.
|
||||
|
||||
Blocks until we have full state for the given room. This only happens for rooms
|
||||
with partial state.
|
||||
|
||||
Returns:
|
||||
A list of hosts in the room, sorted by longest in the room first. (aka.
|
||||
sorted by join with the lowest depth first).
|
||||
"""
|
||||
|
||||
await self._partial_state_room_tracker.await_full_state(room_id)
|
||||
|
||||
return await self.stores.main.get_current_hosts_in_room_ordered(room_id)
|
||||
|
||||
async def get_current_hosts_in_room_or_partial_state_approximation(
|
||||
self, room_id: str
|
||||
) -> Collection[str]:
|
||||
"""Get approximation of current hosts in room based on current state.
|
||||
|
||||
For rooms with full state, this is equivalent to `get_current_hosts_in_room`,
|
||||
with the same order of results.
|
||||
|
||||
For rooms with partial state, no blocking occurs. Instead, the list of hosts
|
||||
in the room at the time of joining is combined with the list of hosts which
|
||||
joined the room afterwards. The returned list may include hosts that are not
|
||||
actually in the room and exclude hosts that are in the room, since we may
|
||||
calculate state incorrectly during the partial state phase. The order of results
|
||||
is arbitrary for rooms with partial state.
|
||||
"""
|
||||
# We have to read this list first to mitigate races with un-partial stating.
|
||||
# This will be empty for rooms with full state.
|
||||
hosts_at_join = await self.stores.main.get_partial_state_servers_at_join(
|
||||
room_id
|
||||
)
|
||||
|
||||
hosts_from_state = await self.stores.main.get_current_hosts_in_room(room_id)
|
||||
|
||||
hosts = set(hosts_at_join)
|
||||
hosts.update(hosts_from_state)
|
||||
|
||||
return hosts
|
||||
|
||||
async def get_users_in_room_with_profiles(
|
||||
self, room_id: str
|
||||
) -> Dict[str, ProfileInfo]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue