diff options
author | Erik Johnston <erik@matrix.org> | 2016-06-03 17:12:48 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-06-03 17:22:13 +0100 |
commit | 05e01f21d7012c1853ff566c8a76aa66087bfbd7 (patch) | |
tree | 3819fa86bda6600ee616c361f336fba070f9e6d7 /synapse/storage/appservice.py | |
parent | Merge branch 'release-v0.16.0' of github.com:matrix-org/synapse into develop (diff) | |
download | synapse-05e01f21d7012c1853ff566c8a76aa66087bfbd7.tar.xz |
Remove event fetching from DB threads
Diffstat (limited to 'synapse/storage/appservice.py')
-rw-r--r-- | synapse/storage/appservice.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/synapse/storage/appservice.py b/synapse/storage/appservice.py index feb9d228ae..ffb7d4a25b 100644 --- a/synapse/storage/appservice.py +++ b/synapse/storage/appservice.py @@ -298,6 +298,7 @@ class ApplicationServiceTransactionStore(SQLBaseStore): dict(txn_id=txn_id, as_id=service.id) ) + @defer.inlineCallbacks def get_oldest_unsent_txn(self, service): """Get the oldest transaction which has not been sent for this service. @@ -308,12 +309,23 @@ class ApplicationServiceTransactionStore(SQLBaseStore): A Deferred which resolves to an AppServiceTransaction or None. """ - return self.runInteraction( + entry = yield self.runInteraction( "get_oldest_unsent_appservice_txn", self._get_oldest_unsent_txn, service ) + if not entry: + defer.returnValue(None) + + event_ids = json.loads(entry["event_ids"]) + + events = yield self.get_events(event_ids) + + defer.returnValue(AppServiceTransaction( + service=service, id=entry["txn_id"], events=events + )) + def _get_oldest_unsent_txn(self, txn, service): # Monotonically increasing txn ids, so just select the smallest # one in the txns table (we delete them when they are sent) @@ -328,12 +340,7 @@ class ApplicationServiceTransactionStore(SQLBaseStore): entry = rows[0] - event_ids = json.loads(entry["event_ids"]) - events = self._get_events_txn(txn, event_ids) - - return AppServiceTransaction( - service=service, id=entry["txn_id"], events=events - ) + return entry def _get_last_txn(self, txn, service_id): txn.execute( |