|
15 | 15 | import itertools
|
16 | 16 | import logging
|
17 | 17 | from queue import Empty, PriorityQueue
|
18 |
| -from typing import Dict, List, Optional, Set, Tuple |
19 |
| - |
20 |
| -from twisted.internet import defer |
| 18 | +from typing import Dict, Iterable, List, Optional, Set, Tuple |
21 | 19 |
|
22 | 20 | from synapse.api.errors import StoreError
|
23 | 21 | from synapse.metrics.background_process_metrics import run_as_background_process
|
@@ -286,17 +284,13 @@ def get_oldest_events_with_depth_in_room_txn(self, txn, room_id):
|
286 | 284 |
|
287 | 285 | return dict(txn)
|
288 | 286 |
|
289 |
| - @defer.inlineCallbacks |
290 |
| - def get_max_depth_of(self, event_ids): |
| 287 | + async def get_max_depth_of(self, event_ids: List[str]) -> int: |
291 | 288 | """Returns the max depth of a set of event IDs
|
292 | 289 |
|
293 | 290 | Args:
|
294 |
| - event_ids (list[str]) |
295 |
| -
|
296 |
| - Returns |
297 |
| - Deferred[int] |
| 291 | + event_ids: The event IDs to calculate the max depth of. |
298 | 292 | """
|
299 |
| - rows = yield self.db_pool.simple_select_many_batch( |
| 293 | + rows = await self.db_pool.simple_select_many_batch( |
300 | 294 | table="events",
|
301 | 295 | column="event_id",
|
302 | 296 | iterable=event_ids,
|
@@ -550,17 +544,16 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):
|
550 | 544 |
|
551 | 545 | return event_results
|
552 | 546 |
|
553 |
| - @defer.inlineCallbacks |
554 |
| - def get_missing_events(self, room_id, earliest_events, latest_events, limit): |
555 |
| - ids = yield self.db_pool.runInteraction( |
| 547 | + async def get_missing_events(self, room_id, earliest_events, latest_events, limit): |
| 548 | + ids = await self.db_pool.runInteraction( |
556 | 549 | "get_missing_events",
|
557 | 550 | self._get_missing_events,
|
558 | 551 | room_id,
|
559 | 552 | earliest_events,
|
560 | 553 | latest_events,
|
561 | 554 | limit,
|
562 | 555 | )
|
563 |
| - events = yield self.get_events_as_list(ids) |
| 556 | + events = await self.get_events_as_list(ids) |
564 | 557 | return events
|
565 | 558 |
|
566 | 559 | def _get_missing_events(self, txn, room_id, earliest_events, latest_events, limit):
|
@@ -595,17 +588,13 @@ def _get_missing_events(self, txn, room_id, earliest_events, latest_events, limi
|
595 | 588 | event_results.reverse()
|
596 | 589 | return event_results
|
597 | 590 |
|
598 |
| - @defer.inlineCallbacks |
599 |
| - def get_successor_events(self, event_ids): |
| 591 | + async def get_successor_events(self, event_ids: Iterable[str]) -> List[str]: |
600 | 592 | """Fetch all events that have the given events as a prev event
|
601 | 593 |
|
602 | 594 | Args:
|
603 |
| - event_ids (iterable[str]) |
604 |
| -
|
605 |
| - Returns: |
606 |
| - Deferred[list[str]] |
| 595 | + event_ids: The events to use as the previous events. |
607 | 596 | """
|
608 |
| - rows = yield self.db_pool.simple_select_many_batch( |
| 597 | + rows = await self.db_pool.simple_select_many_batch( |
609 | 598 | table="event_edges",
|
610 | 599 | column="prev_event_id",
|
611 | 600 | iterable=event_ids,
|
@@ -674,8 +663,7 @@ def _clean_room_for_join_txn(self, txn, room_id):
|
674 | 663 | txn.execute(query, (room_id,))
|
675 | 664 | txn.call_after(self.get_latest_event_ids_in_room.invalidate, (room_id,))
|
676 | 665 |
|
677 |
| - @defer.inlineCallbacks |
678 |
| - def _background_delete_non_state_event_auth(self, progress, batch_size): |
| 666 | + async def _background_delete_non_state_event_auth(self, progress, batch_size): |
679 | 667 | def delete_event_auth(txn):
|
680 | 668 | target_min_stream_id = progress.get("target_min_stream_id_inclusive")
|
681 | 669 | max_stream_id = progress.get("max_stream_id_exclusive")
|
@@ -714,12 +702,12 @@ def delete_event_auth(txn):
|
714 | 702 |
|
715 | 703 | return min_stream_id >= target_min_stream_id
|
716 | 704 |
|
717 |
| - result = yield self.db_pool.runInteraction( |
| 705 | + result = await self.db_pool.runInteraction( |
718 | 706 | self.EVENT_AUTH_STATE_ONLY, delete_event_auth
|
719 | 707 | )
|
720 | 708 |
|
721 | 709 | if not result:
|
722 |
| - yield self.db_pool.updates._end_background_update( |
| 710 | + await self.db_pool.updates._end_background_update( |
723 | 711 | self.EVENT_AUTH_STATE_ONLY
|
724 | 712 | )
|
725 | 713 |
|
|
0 commit comments