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

Fix up state_store naming #12871

Merged
merged 2 commits into from
May 25, 2022
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/12871.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix up the variable `state_store` naming.
4 changes: 2 additions & 2 deletions synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AdminHandler:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastores().main
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof, I would have loved for these to get underscore prefixes while you were renaming them.


async def get_whois(self, user: UserID) -> JsonDict:
connections = []
Expand Down Expand Up @@ -233,7 +233,7 @@ async def export_user_data(self, user_id: str, writer: "ExfiltrationWriter") ->
for event_id in extremities:
if not event_to_unseen_prevs[event_id]:
continue
state = await self.state_store.get_state_for_event(event_id)
state = await self.state_storage.get_state_for_event(event_id)
writer.write_state(room_id, event_id, state)

return writer.finished()
Expand Down
6 changes: 4 additions & 2 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastores().main
self.notifier = hs.get_notifier()
self.state = hs.get_state_handler()
self.state_store = hs.get_storage().state
self.state_storage = hs.get_storage().state
self._auth_handler = hs.get_auth_handler()
self.server_name = hs.hostname

Expand Down Expand Up @@ -203,7 +203,9 @@ async def get_user_ids_changed(
continue

# mapping from event_id -> state_dict
prev_state_ids = await self.state_store.get_state_ids_for_events(event_ids)
prev_state_ids = await self.state_storage.get_state_ids_for_events(
event_ids
)

# Check if we've joined the room? If so we just blindly add all the users to
# the "possibly changed" users.
Expand Down
6 changes: 4 additions & 2 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self, hs: "HomeServer"):

self.store = hs.get_datastores().main
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state
self.federation_client = hs.get_federation_client()
self.state_handler = hs.get_state_handler()
self.server_name = hs.hostname
Expand Down Expand Up @@ -1027,7 +1027,9 @@ async def get_state_ids_for_pdu(self, room_id: str, event_id: str) -> List[str]:
if event.internal_metadata.outlier:
raise NotFoundError("State not known at event %s" % (event_id,))

state_groups = await self.state_store.get_state_groups_ids(room_id, [event_id])
state_groups = await self.state_storage.get_state_groups_ids(
room_id, [event_id]
)

# get_state_groups_ids should return exactly one result
assert len(state_groups) == 1
Expand Down
10 changes: 5 additions & 5 deletions synapse/handlers/federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class FederationEventHandler:
def __init__(self, hs: "HomeServer"):
self._store = hs.get_datastores().main
self._storage = hs.get_storage()
self._state_store = self._storage.state
self._state_storage = self._storage.state

self._state_handler = hs.get_state_handler()
self._event_creation_handler = hs.get_event_creation_handler()
Expand Down Expand Up @@ -533,7 +533,7 @@ async def update_state_for_partial_state_event(
)
return
await self._store.update_state_for_partial_state_event(event, context)
self._state_store.notify_event_un_partial_stated(event.event_id)
self._state_storage.notify_event_un_partial_stated(event.event_id)

async def backfill(
self, dest: str, room_id: str, limit: int, extremities: Collection[str]
Expand Down Expand Up @@ -832,7 +832,7 @@ async def _resolve_state_at_missing_prevs(
event_map = {event_id: event}
try:
# Get the state of the events we know about
ours = await self._state_store.get_state_groups_ids(room_id, seen)
ours = await self._state_storage.get_state_groups_ids(room_id, seen)

# state_maps is a list of mappings from (type, state_key) to event_id
state_maps: List[StateMap[str]] = list(ours.values())
Expand Down Expand Up @@ -1626,7 +1626,7 @@ async def _check_for_soft_fail(
# given state at the event. This should correctly handle cases
# like bans, especially with state res v2.

state_sets_d = await self._state_store.get_state_groups(
state_sets_d = await self._state_storage.get_state_groups(
event.room_id, extrem_ids
)
state_sets: List[Iterable[EventBase]] = list(state_sets_d.values())
Expand Down Expand Up @@ -1895,7 +1895,7 @@ async def _update_context_for_auth_events(

# create a new state group as a delta from the existing one.
prev_group = context.state_group
state_group = await self._state_store.store_state_group(
state_group = await self._state_storage.store_state_group(
event.event_id,
event.room_id,
prev_group=prev_group,
Expand Down
6 changes: 3 additions & 3 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, hs: "HomeServer"):
] = ResponseCache(hs.get_clock(), "initial_sync_cache")
self._event_serializer = hs.get_event_client_serializer()
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state

async def snapshot_all_rooms(
self,
Expand Down Expand Up @@ -198,7 +198,7 @@ async def handle_room(event: RoomsForUser) -> None:
event.stream_ordering,
)
deferred_room_state = run_in_background(
self.state_store.get_state_for_events, [event.event_id]
self.state_storage.get_state_for_events, [event.event_id]
).addCallback(
lambda states: cast(StateMap[EventBase], states[event.event_id])
)
Expand Down Expand Up @@ -355,7 +355,7 @@ async def _room_initial_sync_parted(
member_event_id: str,
is_peeking: bool,
) -> JsonDict:
room_state = await self.state_store.get_state_for_event(member_event_id)
room_state = await self.state_storage.get_state_for_event(member_event_id)

limit = pagin_config.limit if pagin_config else None
if limit is None:
Expand Down
10 changes: 5 additions & 5 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, hs: "HomeServer"):
self.state = hs.get_state_handler()
self.store = hs.get_datastores().main
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state
self._event_serializer = hs.get_event_client_serializer()
self._ephemeral_events_enabled = hs.config.server.enable_ephemeral_messages

Expand Down Expand Up @@ -125,7 +125,7 @@ async def get_room_data(
assert (
membership_event_id is not None
), "check_user_in_room_or_world_readable returned invalid data"
room_state = await self.state_store.get_state_for_events(
room_state = await self.state_storage.get_state_for_events(
[membership_event_id], StateFilter.from_types([key])
)
data = room_state[membership_event_id].get(key)
Expand Down Expand Up @@ -186,7 +186,7 @@ async def get_state_events(

# check whether the user is in the room at that time to determine
# whether they should be treated as peeking.
state_map = await self.state_store.get_state_for_event(
state_map = await self.state_storage.get_state_for_event(
last_event.event_id,
StateFilter.from_types([(EventTypes.Member, user_id)]),
)
Expand All @@ -207,7 +207,7 @@ async def get_state_events(
)

if visible_events:
room_state_events = await self.state_store.get_state_for_events(
room_state_events = await self.state_storage.get_state_for_events(
[last_event.event_id], state_filter=state_filter
)
room_state: Mapping[Any, EventBase] = room_state_events[
Expand Down Expand Up @@ -237,7 +237,7 @@ async def get_state_events(
assert (
membership_event_id is not None
), "check_user_in_room_or_world_readable returned invalid data"
room_state_events = await self.state_store.get_state_for_events(
room_state_events = await self.state_storage.get_state_for_events(
[membership_event_id], state_filter=state_filter
)
room_state = room_state_events[membership_event_id]
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, hs: "HomeServer"):
self.auth = hs.get_auth()
self.store = hs.get_datastores().main
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state
self.clock = hs.get_clock()
self._server_name = hs.hostname
self._room_shutdown_handler = hs.get_room_shutdown_handler()
Expand Down Expand Up @@ -539,7 +539,7 @@ async def get_messages(
(EventTypes.Member, event.sender) for event in events
)

state_ids = await self.state_store.get_state_ids_for_event(
state_ids = await self.state_storage.get_state_ids_for_event(
events[0].event_id, state_filter=state_filter
)

Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ def __init__(self, hs: "HomeServer"):
self.auth = hs.get_auth()
self.store = hs.get_datastores().main
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state
self._relations_handler = hs.get_relations_handler()

async def get_event_context(
Expand Down Expand Up @@ -1293,7 +1293,7 @@ async def filter_evts(events: List[EventBase]) -> List[EventBase]:
# first? Shouldn't we be consistent with /sync?
# https://github.com/matrix-org/matrix-doc/issues/687

state = await self.state_store.get_state_for_events(
state = await self.state_storage.get_state_for_events(
[last_event_id], state_filter=state_filter
)

Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/room_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RoomBatchHandler:
def __init__(self, hs: "HomeServer"):
self.hs = hs
self.store = hs.get_datastores().main
self.state_store = hs.get_storage().state
self.state_storage = hs.get_storage().state
self.event_creation_handler = hs.get_event_creation_handler()
self.room_member_handler = hs.get_room_member_handler()
self.auth = hs.get_auth()
Expand Down Expand Up @@ -141,7 +141,7 @@ async def get_most_recent_full_state_ids_from_event_id_list(
) = await self.store.get_max_depth_of(event_ids)
# mapping from (type, state_key) -> state_event_id
assert most_recent_event_id is not None
prev_state_map = await self.state_store.get_state_ids_for_event(
prev_state_map = await self.state_storage.get_state_ids_for_event(
most_recent_event_id
)
# List of state event ID's
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, hs: "HomeServer"):
self._event_serializer = hs.get_event_client_serializer()
self._relations_handler = hs.get_relations_handler()
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state
self.auth = hs.get_auth()

async def get_old_rooms_from_upgraded_room(self, room_id: str) -> Iterable[str]:
Expand Down Expand Up @@ -677,7 +677,7 @@ async def _calculate_event_contexts(
[(EventTypes.Member, sender) for sender in senders]
)

state = await self.state_store.get_state_for_event(
state = await self.state_storage.get_state_for_event(
last_event_id, state_filter
)

Expand Down
24 changes: 14 additions & 10 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def __init__(self, hs: "HomeServer"):
self.state = hs.get_state_handler()
self.auth = hs.get_auth()
self.storage = hs.get_storage()
self.state_store = self.storage.state
self.state_storage = self.storage.state

# TODO: flush cache entries on subsequent sync request.
# Once we get the next /sync request (ie, one with the same access token
Expand Down Expand Up @@ -643,7 +643,7 @@ async def get_state_after_event(
event: event of interest
state_filter: The state filter used to fetch state from the database.
"""
state_ids = await self.state_store.get_state_ids_for_event(
state_ids = await self.state_storage.get_state_ids_for_event(
event.event_id, state_filter=state_filter or StateFilter.all()
)
if event.is_state():
Expand Down Expand Up @@ -723,7 +723,7 @@ async def compute_summary(
return None

last_event = last_events[-1]
state_ids = await self.state_store.get_state_ids_for_event(
state_ids = await self.state_storage.get_state_ids_for_event(
last_event.event_id,
state_filter=StateFilter.from_types(
[(EventTypes.Name, ""), (EventTypes.CanonicalAlias, "")]
Expand Down Expand Up @@ -901,11 +901,13 @@ async def compute_state_delta(

if full_state:
if batch:
current_state_ids = await self.state_store.get_state_ids_for_event(
batch.events[-1].event_id, state_filter=state_filter
current_state_ids = (
await self.state_storage.get_state_ids_for_event(
batch.events[-1].event_id, state_filter=state_filter
)
)

state_ids = await self.state_store.get_state_ids_for_event(
state_ids = await self.state_storage.get_state_ids_for_event(
batch.events[0].event_id, state_filter=state_filter
)

Expand All @@ -926,7 +928,7 @@ async def compute_state_delta(
elif batch.limited:
if batch:
state_at_timeline_start = (
await self.state_store.get_state_ids_for_event(
await self.state_storage.get_state_ids_for_event(
batch.events[0].event_id, state_filter=state_filter
)
)
Expand Down Expand Up @@ -960,8 +962,10 @@ async def compute_state_delta(
)

if batch:
current_state_ids = await self.state_store.get_state_ids_for_event(
batch.events[-1].event_id, state_filter=state_filter
current_state_ids = (
await self.state_storage.get_state_ids_for_event(
batch.events[-1].event_id, state_filter=state_filter
)
)
else:
# Its not clear how we get here, but empirically we do
Expand Down Expand Up @@ -991,7 +995,7 @@ async def compute_state_delta(
# So we fish out all the member events corresponding to the
# timeline here, and then dedupe any redundant ones below.

state_ids = await self.state_store.get_state_ids_for_event(
state_ids = await self.state_storage.get_state_ids_for_event(
batch.events[0].event_id,
# we only want members!
state_filter=StateFilter.from_types(
Expand Down
6 changes: 3 additions & 3 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(

self.send_email_handler = hs.get_send_email_handler()
self.store = self.hs.get_datastores().main
self.state_store = self.hs.get_storage().state
self.state_storage = self.hs.get_storage().state
self.macaroon_gen = self.hs.get_macaroon_generator()
self.state_handler = self.hs.get_state_handler()
self.storage = hs.get_storage()
Expand Down Expand Up @@ -494,7 +494,7 @@ async def _get_message_vars(
)
else:
# Attempt to check the historical state for the room.
historical_state = await self.state_store.get_state_for_event(
historical_state = await self.state_storage.get_state_for_event(
event.event_id, StateFilter.from_types((type_state_key,))
)
sender_state_event = historical_state.get(type_state_key)
Expand Down Expand Up @@ -767,7 +767,7 @@ async def _make_summary_text_from_member_events(
member_event_ids.append(sender_state_event_id)
else:
# Attempt to check the historical state for the room.
historical_state = await self.state_store.get_state_for_event(
historical_state = await self.state_storage.get_state_for_event(
event_id, StateFilter.from_types((type_state_key,))
)
sender_state_event = historical_state.get(type_state_key)
Expand Down
Loading