|
40 | 40 | from synapse.storage.databases.main.user_directory import SearchResult |
41 | 41 | from synapse.storage.roommember import ProfileInfo |
42 | 42 | from synapse.types import UserID |
| 43 | +from synapse.util.duration import Duration |
43 | 44 | from synapse.util.metrics import Measure |
44 | 45 | from synapse.util.retryutils import NotRetryingDestination |
45 | 46 | from synapse.util.stringutils import non_null_str_or_none |
|
52 | 53 | # Don't refresh a stale user directory entry, using a Federation /profile request, |
53 | 54 | # for 60 seconds. This gives time for other state events to arrive (which will |
54 | 55 | # then be coalesced such that only one /profile request is made). |
55 | | -USER_DIRECTORY_STALE_REFRESH_TIME_MS = 60 * 1000 |
| 56 | +USER_DIRECTORY_STALE_REFRESH_TIME = Duration(seconds=60) |
56 | 57 |
|
57 | 58 | # Maximum number of remote servers that we will attempt to refresh profiles for |
58 | 59 | # in one go. |
59 | 60 | MAX_SERVERS_TO_REFRESH_PROFILES_FOR_IN_ONE_GO = 5 |
60 | 61 |
|
61 | 62 | # As long as we have servers to refresh (without backoff), keep adding more |
62 | 63 | # every 15 seconds. |
63 | | -INTERVAL_TO_ADD_MORE_SERVERS_TO_REFRESH_PROFILES = 15 |
| 64 | +INTERVAL_TO_ADD_MORE_SERVERS_TO_REFRESH_PROFILES = Duration(seconds=15) |
64 | 65 |
|
65 | 66 |
|
66 | 67 | def calculate_time_of_next_retry(now_ts: int, retry_count: int) -> int: |
@@ -137,13 +138,13 @@ def __init__(self, hs: "HomeServer"): |
137 | 138 | # We kick this off so that we don't have to wait for a change before |
138 | 139 | # we start populating the user directory |
139 | 140 | self.clock.call_later( |
140 | | - 0, |
| 141 | + Duration(seconds=0), |
141 | 142 | self.notify_new_event, |
142 | 143 | ) |
143 | 144 |
|
144 | 145 | # Kick off the profile refresh process on startup |
145 | 146 | self._refresh_remote_profiles_call_later = self.clock.call_later( |
146 | | - 10, |
| 147 | + Duration(seconds=10), |
147 | 148 | self.kick_off_remote_profile_refresh_process, |
148 | 149 | ) |
149 | 150 |
|
@@ -550,21 +551,21 @@ async def _handle_possible_remote_profile_change( |
550 | 551 | now_ts = self.clock.time_msec() |
551 | 552 | await self.store.set_remote_user_profile_in_user_dir_stale( |
552 | 553 | user_id, |
553 | | - next_try_at_ms=now_ts + USER_DIRECTORY_STALE_REFRESH_TIME_MS, |
| 554 | + next_try_at_ms=now_ts + USER_DIRECTORY_STALE_REFRESH_TIME.as_millis(), |
554 | 555 | retry_counter=0, |
555 | 556 | ) |
556 | 557 | # Schedule a wake-up to refresh the user directory for this server. |
557 | 558 | # We intentionally wake up this server directly because we don't want |
558 | 559 | # other servers ahead of it in the queue to get in the way of updating |
559 | 560 | # the profile if the server only just sent us an event. |
560 | 561 | self.clock.call_later( |
561 | | - USER_DIRECTORY_STALE_REFRESH_TIME_MS // 1000 + 1, |
| 562 | + USER_DIRECTORY_STALE_REFRESH_TIME + Duration(seconds=1), |
562 | 563 | self.kick_off_remote_profile_refresh_process_for_remote_server, |
563 | 564 | UserID.from_string(user_id).domain, |
564 | 565 | ) |
565 | 566 | # Schedule a wake-up to handle any backoffs that may occur in the future. |
566 | 567 | self.clock.call_later( |
567 | | - 2 * USER_DIRECTORY_STALE_REFRESH_TIME_MS // 1000 + 1, |
| 568 | + USER_DIRECTORY_STALE_REFRESH_TIME * 2 + Duration(seconds=1), |
568 | 569 | self.kick_off_remote_profile_refresh_process, |
569 | 570 | ) |
570 | 571 | return |
@@ -656,7 +657,9 @@ async def _unsafe_refresh_remote_profiles(self) -> None: |
656 | 657 | if not users: |
657 | 658 | return |
658 | 659 | _, _, next_try_at_ts = users[0] |
659 | | - delay = ((next_try_at_ts - self.clock.time_msec()) // 1000) + 2 |
| 660 | + delay = Duration( |
| 661 | + milliseconds=next_try_at_ts - self.clock.time_msec() |
| 662 | + ) + Duration(seconds=2) |
660 | 663 | self._refresh_remote_profiles_call_later = self.clock.call_later( |
661 | 664 | delay, |
662 | 665 | self.kick_off_remote_profile_refresh_process, |
|
0 commit comments