diff options
author | David Baker <dave@matrix.org> | 2016-04-12 13:47:17 +0100 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2016-04-12 13:47:17 +0100 |
commit | 44891b4a0aaa28a3b202d22ef14c6c3b2bca40a5 (patch) | |
tree | 51610a6fbbc2bed662481f81ff6068b47977e491 /synapse/storage/pusher.py | |
parent | Mis-named function (diff) | |
download | synapse-44891b4a0aaa28a3b202d22ef14c6c3b2bca40a5.tar.xz |
Tidy up get_pusher functions
Decodes pushers rows on the main thread rather than the db thread and uses _simple_select_list. Also do the same to the function I copied and factor out the duplication into a helper function.
Diffstat (limited to 'synapse/storage/pusher.py')
-rw-r--r-- | synapse/storage/pusher.py | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py index 90ec06809a..774eda0f3d 100644 --- a/synapse/storage/pusher.py +++ b/synapse/storage/pusher.py @@ -56,43 +56,41 @@ class PusherStore(SQLBaseStore): ) defer.returnValue(ret is not None) - @defer.inlineCallbacks def get_pushers_by_app_id_and_pushkey(self, app_id, pushkey): - def r(txn): - sql = ( - "SELECT * FROM pushers" - " WHERE app_id = ? AND pushkey = ?" - ) - - txn.execute(sql, (app_id, pushkey,)) - rows = self.cursor_to_dict(txn) - - return self._decode_pushers_rows(rows) - - rows = yield self.runInteraction( - "get_pushers_by_app_id_and_pushkey", r - ) - - defer.returnValue(rows) + return self.get_pushers_by({ + "app_id": app_id, + "pushkey": pushkey, + }) - @defer.inlineCallbacks def get_pushers_by_user_id(self, user_id): - def r(txn): - sql = ( - "SELECT * FROM pushers" - " WHERE user_name = ?" - ) - - txn.execute(sql, (user_id,)) - rows = self.cursor_to_dict(txn) - - return self._decode_pushers_rows(rows) + return self.get_pushers_by({ + "user_name": user_id, + }) - result = yield self.runInteraction( - "get_pushers_by_user_id", r + @defer.inlineCallbacks + def get_pushers_by(self, keyvalues): + ret = yield self._simple_select_list( + "pushers", keyvalues, + [ + "id", + "user_name", + "access_token", + "profile_tag", + "kind", + "app_id", + "app_display_name", + "device_display_name", + "pushkey", + "ts", + "lang", + "data", + "last_stream_ordering", + "last_success", + "failing_since", + + ] ) - - defer.returnValue(result) + defer.returnValue(self._decode_pushers_rows(ret)) @defer.inlineCallbacks def get_all_pushers(self): |