-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Move additional tasks to the background worker #8458
Changes from 3 commits
b10327b
8784236
c0af8c4
a09e453
daab41c
609feb5
a50c2b2
74a12fb
702b4ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,15 +43,36 @@ | |
SENTINEL = object() | ||
|
||
|
||
class TransactionStore(SQLBaseStore): | ||
class TransactionWorkerStore(SQLBaseStore): | ||
def __init__(self, database: DatabasePool, db_conn, hs): | ||
super().__init__(database, db_conn, hs) | ||
|
||
self._clock.looping_call(self._start_cleanup_transactions, 30 * 60 * 1000) | ||
|
||
def _start_cleanup_transactions(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we're here should we make things a bit more consistent by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had wondered that. I think it makes sense to do...as long as it is a separate commit. I'll go ahead and do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went ahead and did this, also included this for the changes from #8369 to be consistent. |
||
return run_as_background_process( | ||
"cleanup_transactions", self._cleanup_transactions | ||
) | ||
|
||
async def _cleanup_transactions(self) -> None: | ||
now = self._clock.time_msec() | ||
month_ago = now - 30 * 24 * 60 * 60 * 1000 | ||
|
||
def _cleanup_transactions_txn(txn): | ||
txn.execute("DELETE FROM received_transactions WHERE ts < ?", (month_ago,)) | ||
|
||
await self.db_pool.runInteraction( | ||
"_cleanup_transactions", _cleanup_transactions_txn | ||
) | ||
|
||
|
||
class TransactionStore(TransactionWorkerStore): | ||
"""A collection of queries for handling PDUs. | ||
""" | ||
|
||
def __init__(self, database: DatabasePool, db_conn, hs): | ||
super().__init__(database, db_conn, hs) | ||
|
||
self._clock.looping_call(self._start_cleanup_transactions, 30 * 60 * 1000) | ||
|
||
self._destination_retry_cache = ExpiringCache( | ||
cache_name="get_destination_retry_timings", | ||
clock=self._clock, | ||
|
@@ -266,22 +287,6 @@ def _set_destination_retry_timings( | |
}, | ||
) | ||
|
||
def _start_cleanup_transactions(self): | ||
return run_as_background_process( | ||
"cleanup_transactions", self._cleanup_transactions | ||
) | ||
|
||
async def _cleanup_transactions(self) -> None: | ||
now = self._clock.time_msec() | ||
month_ago = now - 30 * 24 * 60 * 60 * 1000 | ||
|
||
def _cleanup_transactions_txn(txn): | ||
txn.execute("DELETE FROM received_transactions WHERE ts < ?", (month_ago,)) | ||
|
||
await self.db_pool.runInteraction( | ||
"_cleanup_transactions", _cleanup_transactions_txn | ||
) | ||
|
||
async def store_destination_rooms_entries( | ||
self, destinations: Iterable[str], room_id: str, stream_ordering: int, | ||
) -> None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unsure which of these should be the base class? It seems we do have a few layouts:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it depends on if functions in the background updater depend on stuff from the worker or vice versa 🤷