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

Commit

Permalink
Rename vars
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed May 30, 2022
1 parent 179e1c3 commit 4302238
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 126 deletions.
1 change: 0 additions & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def __init__(self, hs: "HomeServer"):
super().__init__(hs)

self.handler = hs.get_federation_handler()
self.storage_controllers = hs.get_storage_controllers()
self._spam_checker = hs.get_spam_checker()
self._federation_event_handler = hs.get_federation_event_handler()
self.state = hs.get_state_handler()
Expand Down
8 changes: 4 additions & 4 deletions synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
class AdminHandler:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastores().main
self.storage_controllers = hs.get_storage_controllers()
self.state_storage_controller = self.storage_controllers.state
self._storage_controllers = hs.get_storage_controllers()
self._state_storage_controller = self._storage_controllers.state

async def get_whois(self, user: UserID) -> JsonDict:
connections = []
Expand Down Expand Up @@ -198,7 +198,7 @@ async def export_user_data(self, user_id: str, writer: "ExfiltrationWriter") ->
from_key = events[-1].internal_metadata.after

events = await filter_events_for_client(
self.storage_controllers, user_id, events
self._storage_controllers, user_id, events
)

writer.write_events(room_id, events)
Expand Down Expand Up @@ -235,7 +235,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_storage_controller.get_state_for_event(
state = await self._state_storage_controller.get_state_for_event(
event_id
)
writer.write_state(room_id, event_id, state)
Expand Down
4 changes: 2 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_storage = hs.get_storage_controllers().state
self._state_storage = hs.get_storage_controllers().state
self._auth_handler = hs.get_auth_handler()
self.server_name = hs.hostname

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

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

Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def get_stream(
class EventHandler:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastores().main
self.storage_controllers = hs.get_storage_controllers()
self._storage_controllers = hs.get_storage_controllers()

async def get_event(
self,
Expand Down Expand Up @@ -177,7 +177,7 @@ async def get_event(
is_peeking = user.to_string() not in users

filtered = await filter_events_for_client(
self.storage_controllers, user.to_string(), [event], is_peeking=is_peeking
self._storage_controllers, user.to_string(), [event], is_peeking=is_peeking
)

if not filtered:
Expand Down
26 changes: 14 additions & 12 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def __init__(self, hs: "HomeServer"):
self.hs = hs

self.store = hs.get_datastores().main
self.storage_controllers = hs.get_storage_controllers()
self.state_storage_controller = self.storage_controllers.state
self._storage_controllers = hs.get_storage_controllers()
self._state_storage_controller = self._storage_controllers.state
self.federation_client = hs.get_federation_client()
self.state_handler = hs.get_state_handler()
self.server_name = hs.hostname
Expand Down Expand Up @@ -324,7 +324,7 @@ async def _maybe_backfill_inner(
# We set `check_history_visibility_only` as we might otherwise get false
# positives from users having been erased.
filtered_extremities = await filter_events_for_server(
self.storage_controllers,
self._storage_controllers,
self.server_name,
events_to_check,
redact=False,
Expand Down Expand Up @@ -660,7 +660,7 @@ async def do_knock(
# in the invitee's sync stream. It is stripped out for all other local users.
event.unsigned["knock_room_state"] = stripped_room_state["knock_state_events"]

context = EventContext.for_outlier(self.storage_controllers)
context = EventContext.for_outlier(self._storage_controllers)
stream_id = await self._federation_event_handler.persist_events_and_notify(
event.room_id, [(event, context)]
)
Expand Down Expand Up @@ -849,7 +849,7 @@ async def on_invite_request(
)
)

context = EventContext.for_outlier(self.storage_controllers)
context = EventContext.for_outlier(self._storage_controllers)
await self._federation_event_handler.persist_events_and_notify(
event.room_id, [(event, context)]
)
Expand Down Expand Up @@ -878,7 +878,7 @@ async def do_remotely_reject_invite(

await self.federation_client.send_leave(host_list, event)

context = EventContext.for_outlier(self.storage_controllers)
context = EventContext.for_outlier(self._storage_controllers)
stream_id = await self._federation_event_handler.persist_events_and_notify(
event.room_id, [(event, context)]
)
Expand Down Expand Up @@ -1027,7 +1027,7 @@ 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_storage_controller.get_state_groups_ids(
state_groups = await self._state_storage_controller.get_state_groups_ids(
room_id, [event_id]
)

Expand Down Expand Up @@ -1079,7 +1079,7 @@ async def on_backfill_request(
)

events = await filter_events_for_server(
self.storage_controllers, origin, events
self._storage_controllers, origin, events
)

return events
Expand Down Expand Up @@ -1112,7 +1112,7 @@ async def get_persisted_pdu(
raise AuthError(403, "Host not in room.")

events = await filter_events_for_server(
self.storage_controllers, origin, [event]
self._storage_controllers, origin, [event]
)
event = events[0]
return event
Expand Down Expand Up @@ -1142,7 +1142,7 @@ async def on_get_missing_events(
)

missing_events = await filter_events_for_server(
self.storage_controllers, origin, missing_events
self._storage_controllers, origin, missing_events
)

return missing_events
Expand Down Expand Up @@ -1484,9 +1484,11 @@ async def _sync_partial_state_room(
# clear the lazy-loading flag.
logger.info("Updating current state for %s", room_id)
assert (
self.storage_controllers.persistence is not None
self._storage_controllers.persistence is not None
), "TODO(faster_joins): support for workers"
await self.storage_controllers.persistence.update_current_state(room_id)
await self._storage_controllers.persistence.update_current_state(
room_id
)

logger.info("Clearing partial-state flag for %s", room_id)
success = await self.store.clear_partial_state_room(room_id)
Expand Down
14 changes: 7 additions & 7 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def __init__(self, hs: "HomeServer"):
]
] = ResponseCache(hs.get_clock(), "initial_sync_cache")
self._event_serializer = hs.get_event_client_serializer()
self.storage_controllers = hs.get_storage_controllers()
self.state_storage_controller = self.storage_controllers.state
self._storage_controllers = hs.get_storage_controllers()
self._state_storage_controller = self._storage_controllers.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_storage_controller.get_state_for_events,
self._state_storage_controller.get_state_for_events,
[event.event_id],
).addCallback(
lambda states: cast(StateMap[EventBase], states[event.event_id])
Expand All @@ -219,7 +219,7 @@ async def handle_room(event: RoomsForUser) -> None:
).addErrback(unwrapFirstError)

messages = await filter_events_for_client(
self.storage_controllers, user_id, messages
self._storage_controllers, user_id, messages
)

start_token = now_token.copy_and_replace(StreamKeyType.ROOM, token)
Expand Down Expand Up @@ -356,7 +356,7 @@ async def _room_initial_sync_parted(
member_event_id: str,
is_peeking: bool,
) -> JsonDict:
room_state = await self.state_storage_controller.get_state_for_event(
room_state = await self._state_storage_controller.get_state_for_event(
member_event_id
)

Expand All @@ -372,7 +372,7 @@ async def _room_initial_sync_parted(
)

messages = await filter_events_for_client(
self.storage_controllers, user_id, messages, is_peeking=is_peeking
self._storage_controllers, user_id, messages, is_peeking=is_peeking
)

start_token = StreamToken.START.copy_and_replace(StreamKeyType.ROOM, token)
Expand Down Expand Up @@ -477,7 +477,7 @@ async def get_receipts() -> List[JsonDict]:
)

messages = await filter_events_for_client(
self.storage_controllers, user_id, messages, is_peeking=is_peeking
self._storage_controllers, user_id, messages, is_peeking=is_peeking
)

start_token = now_token.copy_and_replace(StreamKeyType.ROOM, token)
Expand Down
22 changes: 11 additions & 11 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def __init__(self, hs: "HomeServer"):
self.clock = hs.get_clock()
self.state = hs.get_state_handler()
self.store = hs.get_datastores().main
self.storage_controllers = hs.get_storage_controllers()
self.state_storage_controller = self.storage_controllers.state
self._storage_controllers = hs.get_storage_controllers()
self._state_storage_controller = self._storage_controllers.state
self._event_serializer = hs.get_event_client_serializer()
self._ephemeral_events_enabled = hs.config.server.enable_ephemeral_messages

Expand Down Expand Up @@ -132,7 +132,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_storage_controller.get_state_for_events(
room_state = await self._state_storage_controller.get_state_for_events(
[membership_event_id], StateFilter.from_types([key])
)
data = room_state[membership_event_id].get(key)
Expand Down Expand Up @@ -193,7 +193,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_storage_controller.get_state_for_event(
state_map = await self._state_storage_controller.get_state_for_event(
last_event.event_id,
StateFilter.from_types([(EventTypes.Member, user_id)]),
)
Expand All @@ -206,7 +206,7 @@ async def get_state_events(
is_peeking = not joined

visible_events = await filter_events_for_client(
self.storage_controllers,
self._storage_controllers,
user_id,
[last_event],
filter_send_to_client=False,
Expand All @@ -215,7 +215,7 @@ async def get_state_events(

if visible_events:
room_state_events = (
await self.state_storage_controller.get_state_for_events(
await self._state_storage_controller.get_state_for_events(
[last_event.event_id], state_filter=state_filter
)
)
Expand Down Expand Up @@ -247,7 +247,7 @@ async def get_state_events(
membership_event_id is not None
), "check_user_in_room_or_world_readable returned invalid data"
room_state_events = (
await self.state_storage_controller.get_state_for_events(
await self._state_storage_controller.get_state_for_events(
[membership_event_id], state_filter=state_filter
)
)
Expand Down Expand Up @@ -406,7 +406,7 @@ def __init__(self, hs: "HomeServer"):
self.auth = hs.get_auth()
self._event_auth_handler = hs.get_event_auth_handler()
self.store = hs.get_datastores().main
self.storage_controllers = hs.get_storage_controllers()
self._storage_controllers = hs.get_storage_controllers()
self.state = hs.get_state_handler()
self.clock = hs.get_clock()
self.validator = EventValidator()
Expand Down Expand Up @@ -1021,7 +1021,7 @@ async def create_new_client_event(
# after it is created
if builder.internal_metadata.outlier:
event.internal_metadata.outlier = True
context = EventContext.for_outlier(self.storage_controllers)
context = EventContext.for_outlier(self._storage_controllers)
elif (
event.type == EventTypes.MSC2716_INSERTION
and state_event_ids
Expand Down Expand Up @@ -1434,7 +1434,7 @@ async def persist_and_notify_client_event(
"""
extra_users = extra_users or []

assert self.storage_controllers.persistence is not None
assert self._storage_controllers.persistence is not None
assert self._events_shard_config.should_handle(
self._instance_name, event.room_id
)
Expand Down Expand Up @@ -1668,7 +1668,7 @@ async def persist_and_notify_client_event(
event,
event_pos,
max_stream_token,
) = await self.storage_controllers.persistence.persist_event(
) = await self._storage_controllers.persistence.persist_event(
event, context=context, backfilled=backfilled
)

Expand Down
14 changes: 7 additions & 7 deletions synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def __init__(self, hs: "HomeServer"):
self.hs = hs
self.auth = hs.get_auth()
self.store = hs.get_datastores().main
self.storage_controllers = hs.get_storage_controllers()
self.state_storage_controller = self.storage_controllers.state
self._storage_controllers = hs.get_storage_controllers()
self._state_storage_controller = self._storage_controllers.state
self.clock = hs.get_clock()
self._server_name = hs.hostname
self._room_shutdown_handler = hs.get_room_shutdown_handler()
Expand Down Expand Up @@ -352,7 +352,7 @@ async def _purge_history(
self._purges_in_progress_by_room.add(room_id)
try:
async with self.pagination_lock.write(room_id):
await self.storage_controllers.purge_events.purge_history(
await self._storage_controllers.purge_events.purge_history(
room_id, token, delete_local_events
)
logger.info("[purge] complete")
Expand Down Expand Up @@ -414,7 +414,7 @@ async def purge_room(self, room_id: str, force: bool = False) -> None:
if joined:
raise SynapseError(400, "Users are still joined to this room")

await self.storage_controllers.purge_events.purge_room(room_id)
await self._storage_controllers.purge_events.purge_room(room_id)

async def get_messages(
self,
Expand Down Expand Up @@ -520,7 +520,7 @@ async def get_messages(
events = await event_filter.filter(events)

events = await filter_events_for_client(
self.storage_controllers,
self._storage_controllers,
user_id,
events,
is_peeking=(member_event_id is None),
Expand All @@ -542,7 +542,7 @@ async def get_messages(
(EventTypes.Member, event.sender) for event in events
)

state_ids = await self.state_storage_controller.get_state_ids_for_event(
state_ids = await self._state_storage_controller.get_state_ids_for_event(
events[0].event_id, state_filter=state_filter
)

Expand Down Expand Up @@ -656,7 +656,7 @@ async def _shutdown_and_purge_room(
400, "Users are still joined to this room"
)

await self.storage_controllers.purge_events.purge_room(room_id)
await self._storage_controllers.purge_events.purge_room(room_id)

logger.info("complete")
self._delete_by_id[delete_id].status = DeleteStatus.STATUS_COMPLETE
Expand Down
Loading

0 comments on commit 4302238

Please sign in to comment.