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

Ensure that get_datastores().main is typed #12070

Merged
merged 2 commits into from
Feb 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/12069.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor typing fixes.
1 change: 1 addition & 0 deletions changelog.d/12070.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove legacy `HomeServer.get_datastore()`.
3 changes: 2 additions & 1 deletion synapse/storage/databases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

if TYPE_CHECKING:
from synapse.server import HomeServer
from synapse.storage.databases.main import DataStore

logger = logging.getLogger(__name__)

Expand All @@ -44,7 +45,7 @@ class Databases(Generic[DataStoreT]):
"""

databases: List[DatabasePool]
main: DataStoreT
main: "DataStore" # FIXME: #11165: actually an instance of `main_store_class`
Copy link
Contributor Author

@squahtx squahtx Feb 23, 2022

Choose a reason for hiding this comment

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

The type hint is strictly inaccurate, but it's more or less a translation of what we had previously, where get_datastore() claimed to return a DataStore.

state: StateGroupDataStore
persist_events: Optional[PersistEventsStore]

Expand Down
9 changes: 4 additions & 5 deletions synapse/storage/persist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,13 @@ async def _persist_event_batch(
)

for room_id, ev_ctx_rm in events_by_room.items():
latest_event_ids = (
latest_event_ids = set(
await self.main_store.get_latest_event_ids_in_room(room_id)
)
new_latest_event_ids = await self._calculate_new_extremities(
room_id, ev_ctx_rm, latest_event_ids
)

latest_event_ids = set(latest_event_ids)
if new_latest_event_ids == latest_event_ids:
# No change in extremities, so no change in state
continue
Expand Down Expand Up @@ -567,7 +566,7 @@ async def _persist_event_batch(
)
if not is_still_joined:
logger.info("Server no longer in room %s", room_id)
latest_event_ids = []
latest_event_ids = set()
current_state = {}
delta.no_longer_in_room = True

Expand Down Expand Up @@ -906,9 +905,9 @@ async def _prune_extremities(
# Ideally we'd figure out a way of still being able to drop old
# dummy events that reference local events, but this is good enough
# as a first cut.
events_to_check = [event]
events_to_check: Collection[EventBase] = [event]
while events_to_check:
new_events = set()
new_events: Set[str] = set()
for event_to_check in events_to_check:
if self.is_mine_id(event_to_check.sender):
if event_to_check.type != EventTypes.Dummy:
Expand Down