summary refs log tree commit diff
path: root/synapse/federation/persistence.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-10-20 17:42:11 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2020-10-20 17:42:11 +0100
commit41ac1232b5bd78f2dff5edd6c8b04c5ceb2aa87c (patch)
tree8c170802b61dcf7c200b8b4fd7b9e37a2ca51d0a /synapse/federation/persistence.py
parentMerge commit 'e00816ad9' into anoa/dinsic_release_1_21_x (diff)
parentConvert additional database code to async/await. (#8195) (diff)
downloadsynapse-41ac1232b5bd78f2dff5edd6c8b04c5ceb2aa87c.tar.xz
Merge commit '5c03134d0' into anoa/dinsic_release_1_21_x
* commit '5c03134d0':
  Convert additional database code to async/await. (#8195)
  Define StateMap as immutable and add a MutableStateMap type. (#8183)
  Move and refactor LoginRestServlet helper methods (#8182)
Diffstat (limited to 'synapse/federation/persistence.py')
-rw-r--r--synapse/federation/persistence.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/synapse/federation/persistence.py b/synapse/federation/persistence.py

index 769cd5de28..de1fe7da38 100644 --- a/synapse/federation/persistence.py +++ b/synapse/federation/persistence.py
@@ -20,6 +20,7 @@ These actions are mostly only used by the :py:mod:`.replication` module. """ import logging +from typing import Optional, Tuple from synapse.federation.units import Transaction from synapse.logging.utils import log_function @@ -36,25 +37,27 @@ class TransactionActions(object): self.store = datastore @log_function - def have_responded(self, origin, transaction): - """ Have we already responded to a transaction with the same id and + async def have_responded( + self, origin: str, transaction: Transaction + ) -> Optional[Tuple[int, JsonDict]]: + """Have we already responded to a transaction with the same id and origin? Returns: - Deferred: Results in `None` if we have not previously responded to - this transaction or a 2-tuple of `(int, dict)` representing the - response code and response body. + `None` if we have not previously responded to this transaction or a + 2-tuple of `(int, dict)` representing the response code and response body. """ - if not transaction.transaction_id: + transaction_id = transaction.transaction_id # type: ignore + if not transaction_id: raise RuntimeError("Cannot persist a transaction with no transaction_id") - return self.store.get_received_txn_response(transaction.transaction_id, origin) + return await self.store.get_received_txn_response(transaction_id, origin) @log_function async def set_response( self, origin: str, transaction: Transaction, code: int, response: JsonDict ) -> None: - """ Persist how we responded to a transaction. + """Persist how we responded to a transaction. """ transaction_id = transaction.transaction_id # type: ignore if not transaction_id: