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

Commit 5313899

Browse files
committed
Merge commit 'd58fda99f' into anoa/dinsic_release_1_21_x
* commit 'd58fda99f': Convert `event_push_actions`, `registration`, and `roommember` datastores to async (#8197) Only return devices with keys from `/federation/v1/user/devices/` (#8198)
2 parents b7672ff + d58fda9 commit 5313899

File tree

6 files changed

+171
-163
lines changed

6 files changed

+171
-163
lines changed

changelog.d/8197.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert various parts of the codebase to async/await.

changelog.d/8198.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimise `/federation/v1/user/devices/` API by only returning devices with encryption keys.

synapse/storage/databases/main/devices.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,7 @@ def _get_devices_with_keys_by_user_txn(
498498
) -> Tuple[int, List[JsonDict]]:
499499
now_stream_id = self._device_list_id_gen.get_current_token()
500500

501-
devices = self._get_e2e_device_keys_txn(
502-
txn, [(user_id, None)], include_all_devices=True
503-
)
501+
devices = self._get_e2e_device_keys_txn(txn, [(user_id, None)])
504502

505503
if devices:
506504
user_devices = devices[user_id]

synapse/storage/databases/main/event_push_actions.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
import logging
18-
from typing import List
18+
from typing import Dict, List, Union
1919

2020
from synapse.metrics.background_process_metrics import run_as_background_process
2121
from synapse.storage._base import LoggingTransaction, SQLBaseStore, db_to_json
@@ -383,19 +383,20 @@ def get_no_receipt(txn):
383383
# Now return the first `limit`
384384
return notifs[:limit]
385385

386-
def get_if_maybe_push_in_range_for_user(self, user_id, min_stream_ordering):
386+
async def get_if_maybe_push_in_range_for_user(
387+
self, user_id: str, min_stream_ordering: int
388+
) -> bool:
387389
"""A fast check to see if there might be something to push for the
388390
user since the given stream ordering. May return false positives.
389391
390392
Useful to know whether to bother starting a pusher on start up or not.
391393
392394
Args:
393-
user_id (str)
394-
min_stream_ordering (int)
395+
user_id
396+
min_stream_ordering
395397
396398
Returns:
397-
Deferred[bool]: True if there may be push to process, False if
398-
there definitely isn't.
399+
True if there may be push to process, False if there definitely isn't.
399400
"""
400401

401402
def _get_if_maybe_push_in_range_for_user_txn(txn):
@@ -408,22 +409,20 @@ def _get_if_maybe_push_in_range_for_user_txn(txn):
408409
txn.execute(sql, (user_id, min_stream_ordering))
409410
return bool(txn.fetchone())
410411

411-
return self.db_pool.runInteraction(
412+
return await self.db_pool.runInteraction(
412413
"get_if_maybe_push_in_range_for_user",
413414
_get_if_maybe_push_in_range_for_user_txn,
414415
)
415416

416-
async def add_push_actions_to_staging(self, event_id, user_id_actions):
417+
async def add_push_actions_to_staging(
418+
self, event_id: str, user_id_actions: Dict[str, List[Union[dict, str]]]
419+
) -> None:
417420
"""Add the push actions for the event to the push action staging area.
418421
419422
Args:
420-
event_id (str)
421-
user_id_actions (dict[str, list[dict|str])]): A dictionary mapping
422-
user_id to list of push actions, where an action can either be
423-
a string or dict.
424-
425-
Returns:
426-
Deferred
423+
event_id
424+
user_id_actions: A mapping of user_id to list of push actions, where
425+
an action can either be a string or dict.
427426
"""
428427

429428
if not user_id_actions:
@@ -507,7 +506,7 @@ def _find_stream_orderings_for_times_txn(self, txn):
507506
"Found stream ordering 1 day ago: it's %d", self.stream_ordering_day_ago
508507
)
509508

510-
def find_first_stream_ordering_after_ts(self, ts):
509+
async def find_first_stream_ordering_after_ts(self, ts: int) -> int:
511510
"""Gets the stream ordering corresponding to a given timestamp.
512511
513512
Specifically, finds the stream_ordering of the first event that was
@@ -516,13 +515,12 @@ def find_first_stream_ordering_after_ts(self, ts):
516515
relatively slow.
517516
518517
Args:
519-
ts (int): timestamp in millis
518+
ts: timestamp in millis
520519
521520
Returns:
522-
Deferred[int]: stream ordering of the first event received on/after
523-
the timestamp
521+
stream ordering of the first event received on/after the timestamp
524522
"""
525-
return self.db_pool.runInteraction(
523+
return await self.db_pool.runInteraction(
526524
"_find_first_stream_ordering_after_ts_txn",
527525
self._find_first_stream_ordering_after_ts_txn,
528526
ts,

0 commit comments

Comments
 (0)