mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-07-20 21:59:00 -04:00
Convert state and stream stores and related code to async (#8194)
This commit is contained in:
parent
b055dc9322
commit
aec7085179
7 changed files with 51 additions and 45 deletions
|
@ -14,8 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from twisted.internet import defer
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
from synapse.storage._base import SQLBaseStore
|
||||
|
||||
|
@ -23,7 +22,9 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class StateDeltasStore(SQLBaseStore):
|
||||
def get_current_state_deltas(self, prev_stream_id: int, max_stream_id: int):
|
||||
async def get_current_state_deltas(
|
||||
self, prev_stream_id: int, max_stream_id: int
|
||||
) -> Tuple[int, List[Dict[str, Any]]]:
|
||||
"""Fetch a list of room state changes since the given stream id
|
||||
|
||||
Each entry in the result contains the following fields:
|
||||
|
@ -37,12 +38,12 @@ class StateDeltasStore(SQLBaseStore):
|
|||
if it's new state.
|
||||
|
||||
Args:
|
||||
prev_stream_id (int): point to get changes since (exclusive)
|
||||
max_stream_id (int): the point that we know has been correctly persisted
|
||||
prev_stream_id: point to get changes since (exclusive)
|
||||
max_stream_id: the point that we know has been correctly persisted
|
||||
- ie, an upper limit to return changes from.
|
||||
|
||||
Returns:
|
||||
Deferred[tuple[int, list[dict]]: A tuple consisting of:
|
||||
A tuple consisting of:
|
||||
- the stream id which these results go up to
|
||||
- list of current_state_delta_stream rows. If it is empty, we are
|
||||
up to date.
|
||||
|
@ -58,7 +59,7 @@ class StateDeltasStore(SQLBaseStore):
|
|||
# if the CSDs haven't changed between prev_stream_id and now, we
|
||||
# know for certain that they haven't changed between prev_stream_id and
|
||||
# max_stream_id.
|
||||
return defer.succeed((max_stream_id, []))
|
||||
return (max_stream_id, [])
|
||||
|
||||
def get_current_state_deltas_txn(txn):
|
||||
# First we calculate the max stream id that will give us less than
|
||||
|
@ -102,7 +103,7 @@ class StateDeltasStore(SQLBaseStore):
|
|||
txn.execute(sql, (prev_stream_id, clipped_stream_id))
|
||||
return clipped_stream_id, self.db_pool.cursor_to_dict(txn)
|
||||
|
||||
return self.db_pool.runInteraction(
|
||||
return await self.db_pool.runInteraction(
|
||||
"get_current_state_deltas", get_current_state_deltas_txn
|
||||
)
|
||||
|
||||
|
@ -114,8 +115,8 @@ class StateDeltasStore(SQLBaseStore):
|
|||
retcol="COALESCE(MAX(stream_id), -1)",
|
||||
)
|
||||
|
||||
def get_max_stream_id_in_current_state_deltas(self):
|
||||
return self.db_pool.runInteraction(
|
||||
async def get_max_stream_id_in_current_state_deltas(self):
|
||||
return await self.db_pool.runInteraction(
|
||||
"get_max_stream_id_in_current_state_deltas",
|
||||
self._get_max_stream_id_in_current_state_deltas_txn,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue