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

Commit f3fd855

Browse files
authored
Minor typing fixes for synapse/storage/persist_events.py (#12069)
Signed-off-by: Sean Quah <[email protected]>
1 parent 54e74cc commit f3fd855

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

Diff for: changelog.d/12069.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Minor typing fixes.

Diff for: synapse/storage/databases/main/events.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async def _persist_events_and_state_updates(
130130
*,
131131
current_state_for_room: Dict[str, StateMap[str]],
132132
state_delta_for_room: Dict[str, DeltaState],
133-
new_forward_extremeties: Dict[str, List[str]],
133+
new_forward_extremities: Dict[str, Set[str]],
134134
use_negative_stream_ordering: bool = False,
135135
inhibit_local_membership_updates: bool = False,
136136
) -> None:
@@ -143,7 +143,7 @@ async def _persist_events_and_state_updates(
143143
the room based on forward extremities
144144
state_delta_for_room: Map from room_id to the delta to apply to
145145
room state
146-
new_forward_extremities: Map from room_id to list of event IDs
146+
new_forward_extremities: Map from room_id to set of event IDs
147147
that are the new forward extremities of the room.
148148
use_negative_stream_ordering: Whether to start stream_ordering on
149149
the negative side and decrement. This should be set as True
@@ -193,7 +193,7 @@ async def _persist_events_and_state_updates(
193193
events_and_contexts=events_and_contexts,
194194
inhibit_local_membership_updates=inhibit_local_membership_updates,
195195
state_delta_for_room=state_delta_for_room,
196-
new_forward_extremeties=new_forward_extremeties,
196+
new_forward_extremities=new_forward_extremities,
197197
)
198198
persist_event_counter.inc(len(events_and_contexts))
199199

@@ -220,7 +220,7 @@ async def _persist_events_and_state_updates(
220220
for room_id, new_state in current_state_for_room.items():
221221
self.store.get_current_state_ids.prefill((room_id,), new_state)
222222

223-
for room_id, latest_event_ids in new_forward_extremeties.items():
223+
for room_id, latest_event_ids in new_forward_extremities.items():
224224
self.store.get_latest_event_ids_in_room.prefill(
225225
(room_id,), list(latest_event_ids)
226226
)
@@ -334,8 +334,8 @@ def _persist_events_txn(
334334
events_and_contexts: List[Tuple[EventBase, EventContext]],
335335
inhibit_local_membership_updates: bool = False,
336336
state_delta_for_room: Optional[Dict[str, DeltaState]] = None,
337-
new_forward_extremeties: Optional[Dict[str, List[str]]] = None,
338-
):
337+
new_forward_extremities: Optional[Dict[str, Set[str]]] = None,
338+
) -> None:
339339
"""Insert some number of room events into the necessary database tables.
340340
341341
Rejected events are only inserted into the events table, the events_json table,
@@ -353,13 +353,13 @@ def _persist_events_txn(
353353
from the database. This is useful when retrying due to
354354
IntegrityError.
355355
state_delta_for_room: The current-state delta for each room.
356-
new_forward_extremetie: The new forward extremities for each room.
356+
new_forward_extremities: The new forward extremities for each room.
357357
For each room, a list of the event ids which are the forward
358358
extremities.
359359
360360
"""
361361
state_delta_for_room = state_delta_for_room or {}
362-
new_forward_extremeties = new_forward_extremeties or {}
362+
new_forward_extremities = new_forward_extremities or {}
363363

364364
all_events_and_contexts = events_and_contexts
365365

@@ -372,7 +372,7 @@ def _persist_events_txn(
372372

373373
self._update_forward_extremities_txn(
374374
txn,
375-
new_forward_extremities=new_forward_extremeties,
375+
new_forward_extremities=new_forward_extremities,
376376
max_stream_order=max_stream_order,
377377
)
378378

@@ -1158,7 +1158,10 @@ def _upsert_room_version_txn(self, txn: LoggingTransaction, room_id: str):
11581158
)
11591159

11601160
def _update_forward_extremities_txn(
1161-
self, txn, new_forward_extremities, max_stream_order
1161+
self,
1162+
txn: LoggingTransaction,
1163+
new_forward_extremities: Dict[str, Set[str]],
1164+
max_stream_order: int,
11621165
):
11631166
for room_id in new_forward_extremities.keys():
11641167
self.db_pool.simple_delete_txn(

Diff for: synapse/storage/persist_events.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -427,21 +427,21 @@ async def _persist_event_batch(
427427
# NB: Assumes that we are only persisting events for one room
428428
# at a time.
429429

430-
# map room_id->list[event_ids] giving the new forward
430+
# map room_id->set[event_ids] giving the new forward
431431
# extremities in each room
432-
new_forward_extremeties = {}
432+
new_forward_extremities: Dict[str, Set[str]] = {}
433433

434434
# map room_id->(type,state_key)->event_id tracking the full
435435
# state in each room after adding these events.
436436
# This is simply used to prefill the get_current_state_ids
437437
# cache
438-
current_state_for_room = {}
438+
current_state_for_room: Dict[str, StateMap[str]] = {}
439439

440440
# map room_id->(to_delete, to_insert) where to_delete is a list
441441
# of type/state keys to remove from current state, and to_insert
442442
# is a map (type,key)->event_id giving the state delta in each
443443
# room
444-
state_delta_for_room = {}
444+
state_delta_for_room: Dict[str, DeltaState] = {}
445445

446446
# Set of remote users which were in rooms the server has left. We
447447
# should check if we still share any rooms and if not we mark their
@@ -460,14 +460,13 @@ async def _persist_event_batch(
460460
)
461461

462462
for room_id, ev_ctx_rm in events_by_room.items():
463-
latest_event_ids = (
463+
latest_event_ids = set(
464464
await self.main_store.get_latest_event_ids_in_room(room_id)
465465
)
466466
new_latest_event_ids = await self._calculate_new_extremities(
467467
room_id, ev_ctx_rm, latest_event_ids
468468
)
469469

470-
latest_event_ids = set(latest_event_ids)
471470
if new_latest_event_ids == latest_event_ids:
472471
# No change in extremities, so no change in state
473472
continue
@@ -478,7 +477,7 @@ async def _persist_event_batch(
478477
# extremities, so we'll `continue` above and skip this bit.)
479478
assert new_latest_event_ids, "No forward extremities left!"
480479

481-
new_forward_extremeties[room_id] = new_latest_event_ids
480+
new_forward_extremities[room_id] = new_latest_event_ids
482481

483482
len_1 = (
484483
len(latest_event_ids) == 1
@@ -533,7 +532,7 @@ async def _persist_event_batch(
533532
# extremities, so we'll `continue` above and skip this bit.)
534533
assert new_latest_event_ids, "No forward extremities left!"
535534

536-
new_forward_extremeties[room_id] = new_latest_event_ids
535+
new_forward_extremities[room_id] = new_latest_event_ids
537536

538537
# If either are not None then there has been a change,
539538
# and we need to work out the delta (or use that
@@ -567,7 +566,7 @@ async def _persist_event_batch(
567566
)
568567
if not is_still_joined:
569568
logger.info("Server no longer in room %s", room_id)
570-
latest_event_ids = []
569+
latest_event_ids = set()
571570
current_state = {}
572571
delta.no_longer_in_room = True
573572

@@ -582,7 +581,7 @@ async def _persist_event_batch(
582581
chunk,
583582
current_state_for_room=current_state_for_room,
584583
state_delta_for_room=state_delta_for_room,
585-
new_forward_extremeties=new_forward_extremeties,
584+
new_forward_extremities=new_forward_extremities,
586585
use_negative_stream_ordering=backfilled,
587586
inhibit_local_membership_updates=backfilled,
588587
)
@@ -596,7 +595,7 @@ async def _calculate_new_extremities(
596595
room_id: str,
597596
event_contexts: List[Tuple[EventBase, EventContext]],
598597
latest_event_ids: Collection[str],
599-
):
598+
) -> Set[str]:
600599
"""Calculates the new forward extremities for a room given events to
601600
persist.
602601
@@ -906,9 +905,9 @@ async def _prune_extremities(
906905
# Ideally we'd figure out a way of still being able to drop old
907906
# dummy events that reference local events, but this is good enough
908907
# as a first cut.
909-
events_to_check = [event]
908+
events_to_check: Collection[EventBase] = [event]
910909
while events_to_check:
911-
new_events = set()
910+
new_events: Set[str] = set()
912911
for event_to_check in events_to_check:
913912
if self.is_mine_id(event_to_check.sender):
914913
if event_to_check.type != EventTypes.Dummy:

0 commit comments

Comments
 (0)