diff options
author | Kegsay <kegsay@gmail.com> | 2016-11-14 12:45:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-14 12:45:30 +0000 |
commit | 9355a5c42b4003ea8749ed077c812ebba9a5f7cf (patch) | |
tree | d35934cc8031e0ddb4dfc2ad6f028e628d226481 /synapse/rest/client/v2_alpha/sendtodevice.py | |
parent | Merge pull request #1625 from DanielDent/patch-1 (diff) | |
parent | Clean transactions based on time. Add HttpTransactionCache tests. (diff) | |
download | synapse-9355a5c42b4003ea8749ed077c812ebba9a5f7cf.tar.xz |
Merge pull request #1624 from matrix-org/kegan/idempotent-requests
Store Promise<Response> instead of Response for HTTP API transactions
Diffstat (limited to 'synapse/rest/client/v2_alpha/sendtodevice.py')
-rw-r--r-- | synapse/rest/client/v2_alpha/sendtodevice.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/synapse/rest/client/v2_alpha/sendtodevice.py b/synapse/rest/client/v2_alpha/sendtodevice.py index 5975164b37..ac660669f3 100644 --- a/synapse/rest/client/v2_alpha/sendtodevice.py +++ b/synapse/rest/client/v2_alpha/sendtodevice.py @@ -19,7 +19,7 @@ from twisted.internet import defer from synapse.http import servlet from synapse.http.servlet import parse_json_object_from_request -from synapse.rest.client.v1.transactions import HttpTransactionStore +from synapse.rest.client.transactions import HttpTransactionCache from ._base import client_v2_patterns @@ -40,18 +40,16 @@ class SendToDeviceRestServlet(servlet.RestServlet): super(SendToDeviceRestServlet, self).__init__() self.hs = hs self.auth = hs.get_auth() - self.txns = HttpTransactionStore() + self.txns = HttpTransactionCache(hs.get_clock()) self.device_message_handler = hs.get_device_message_handler() - @defer.inlineCallbacks def on_PUT(self, request, message_type, txn_id): - try: - defer.returnValue( - self.txns.get_client_transaction(request, txn_id) - ) - except KeyError: - pass + return self.txns.fetch_or_execute_request( + request, self._put, request, message_type, txn_id + ) + @defer.inlineCallbacks + def _put(self, request, message_type, txn_id): requester = yield self.auth.get_user_by_req(request) content = parse_json_object_from_request(request) @@ -63,7 +61,6 @@ class SendToDeviceRestServlet(servlet.RestServlet): ) response = (200, {}) - self.txns.store_client_transaction(request, txn_id, response) defer.returnValue(response) |