|
37 | 37 | RoomSyncConfig, |
38 | 38 | ) |
39 | 39 | from synapse.util.caches.descriptors import cached |
40 | | -from synapse.util.constants import ( |
41 | | - MILLISECONDS_PER_SECOND, |
42 | | - ONE_DAY_SECONDS, |
43 | | - ONE_HOUR_SECONDS, |
44 | | - ONE_MINUTE_SECONDS, |
45 | | -) |
| 40 | +from synapse.util.duration import Duration |
46 | 41 | from synapse.util.json import json_encoder |
47 | 42 |
|
48 | 43 | if TYPE_CHECKING: |
|
57 | 52 | # position. We don't want to update it on every use to avoid excessive |
58 | 53 | # writes, but we want it to be reasonably up-to-date to help with |
59 | 54 | # cleaning up old connection positions. |
60 | | -UPDATE_INTERVAL_LAST_USED_TS_MS = 5 * ONE_MINUTE_SECONDS * MILLISECONDS_PER_SECOND |
| 55 | +UPDATE_INTERVAL_LAST_USED_TS = Duration(minutes=5) |
61 | 56 |
|
62 | 57 | # Time in milliseconds the connection hasn't been used before we consider it |
63 | 58 | # expired and delete it. |
64 | | -CONNECTION_EXPIRY_MS = 7 * ONE_DAY_SECONDS * MILLISECONDS_PER_SECOND |
| 59 | +CONNECTION_EXPIRY = Duration(days=7) |
65 | 60 |
|
66 | 61 | # How often we run the background process to delete old sliding sync connections. |
67 | | -CONNECTION_EXPIRY_FREQUENCY_MS = ONE_HOUR_SECONDS * MILLISECONDS_PER_SECOND |
| 62 | +CONNECTION_EXPIRY_FREQUENCY = Duration(hours=1) |
68 | 63 |
|
69 | 64 |
|
70 | 65 | class SlidingSyncStore(SQLBaseStore): |
@@ -101,7 +96,7 @@ def __init__( |
101 | 96 | if self.hs.config.worker.run_background_tasks: |
102 | 97 | self.clock.looping_call( |
103 | 98 | self.delete_old_sliding_sync_connections, |
104 | | - CONNECTION_EXPIRY_FREQUENCY_MS, |
| 99 | + CONNECTION_EXPIRY_FREQUENCY.as_millis(), |
105 | 100 | ) |
106 | 101 |
|
107 | 102 | async def get_latest_bump_stamp_for_room( |
@@ -430,7 +425,10 @@ def _get_and_clear_connection_positions_txn( |
430 | 425 | # Update the `last_used_ts` if it's due to be updated. We don't update |
431 | 426 | # every time to avoid excessive writes. |
432 | 427 | now = self.clock.time_msec() |
433 | | - if last_used_ts is None or now - last_used_ts > UPDATE_INTERVAL_LAST_USED_TS_MS: |
| 428 | + if ( |
| 429 | + last_used_ts is None |
| 430 | + or now - last_used_ts > UPDATE_INTERVAL_LAST_USED_TS.as_millis() |
| 431 | + ): |
434 | 432 | self.db_pool.simple_update_txn( |
435 | 433 | txn, |
436 | 434 | table="sliding_sync_connections", |
@@ -532,7 +530,7 @@ def _get_and_clear_connection_positions_txn( |
532 | 530 | @wrap_as_background_process("delete_old_sliding_sync_connections") |
533 | 531 | async def delete_old_sliding_sync_connections(self) -> None: |
534 | 532 | """Delete sliding sync connections that have not been used for a long time.""" |
535 | | - cutoff_ts = self.clock.time_msec() - CONNECTION_EXPIRY_MS |
| 533 | + cutoff_ts = self.clock.time_msec() - CONNECTION_EXPIRY.as_millis() |
536 | 534 |
|
537 | 535 | def delete_old_sliding_sync_connections_txn(txn: LoggingTransaction) -> None: |
538 | 536 | sql = """ |
|
0 commit comments