From 8a76094965635eb2afd501038ea3c09f88416ce2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 11 Apr 2016 18:00:03 +0100 Subject: Add get endpoint for pushers As per https://github.com/matrix-org/matrix-doc/pull/308 --- synapse/storage/pusher.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'synapse/storage') diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py index 19888a8e76..11feab72de 100644 --- a/synapse/storage/pusher.py +++ b/synapse/storage/pusher.py @@ -75,6 +75,25 @@ class PusherStore(SQLBaseStore): defer.returnValue(rows) + @defer.inlineCallbacks + def get_pushers_by_app_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) + + result = yield self.runInteraction( + "get_pushers_by_user_id", r + ) + + defer.returnValue(result) + @defer.inlineCallbacks def get_all_pushers(self): def get_pushers(txn): -- cgit 1.5.1 From 7b39bcdaae70e3a167d38bb1cdf8e6d4d95f0cca Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 13:35:08 +0100 Subject: Mis-named function --- synapse/rest/client/v1/pusher.py | 2 +- synapse/storage/pusher.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'synapse/storage') diff --git a/synapse/rest/client/v1/pusher.py b/synapse/rest/client/v1/pusher.py index 321eadbc24..d792dac648 100644 --- a/synapse/rest/client/v1/pusher.py +++ b/synapse/rest/client/v1/pusher.py @@ -37,7 +37,7 @@ class PushersRestServlet(ClientV1RestServlet): requester = yield self.auth.get_user_by_req(request) user = requester.user - pushers = yield self.hs.get_datastore().get_pushers_by_app_user_id( + pushers = yield self.hs.get_datastore().get_pushers_by_user_id( user.to_string() ) diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py index 11feab72de..90ec06809a 100644 --- a/synapse/storage/pusher.py +++ b/synapse/storage/pusher.py @@ -76,7 +76,7 @@ class PusherStore(SQLBaseStore): defer.returnValue(rows) @defer.inlineCallbacks - def get_pushers_by_app_user_id(self, user_id): + def get_pushers_by_user_id(self, user_id): def r(txn): sql = ( "SELECT * FROM pushers" -- cgit 1.5.1 From 44891b4a0aaa28a3b202d22ef14c6c3b2bca40a5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 13:47:17 +0100 Subject: 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. --- synapse/storage/pusher.py | 62 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'synapse/storage') 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): -- cgit 1.5.1 From c1267d04c5fdd900ea917682056b1239495f90ee Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 13:55:32 +0100 Subject: Oops, forgot the desc. --- synapse/storage/pusher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'synapse/storage') diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py index 774eda0f3d..e0b80d64f4 100644 --- a/synapse/storage/pusher.py +++ b/synapse/storage/pusher.py @@ -88,7 +88,7 @@ class PusherStore(SQLBaseStore): "last_success", "failing_since", - ] + ], desc="get_pushers_by" ) defer.returnValue(self._decode_pushers_rows(ret)) -- cgit 1.5.1 From 7984ffdc6a1850f6e0eb46562c53a10ce31e09b0 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 13:55:57 +0100 Subject: Unneccessarywhitespaceisunnecessary --- synapse/storage/pusher.py | 1 - 1 file changed, 1 deletion(-) (limited to 'synapse/storage') diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py index e0b80d64f4..e64c0dce0a 100644 --- a/synapse/storage/pusher.py +++ b/synapse/storage/pusher.py @@ -87,7 +87,6 @@ class PusherStore(SQLBaseStore): "last_stream_ordering", "last_success", "failing_since", - ], desc="get_pushers_by" ) defer.returnValue(self._decode_pushers_rows(ret)) -- cgit 1.5.1