diff options
author | Neil Johnson <neil@matrix.org> | 2018-08-01 10:21:56 +0100 |
---|---|---|
committer | Neil Johnson <neil@matrix.org> | 2018-08-01 10:21:56 +0100 |
commit | 7931393495c76eef0af9b91c7904c88943197054 (patch) | |
tree | 2cde24c4b2f49ec0f21bd78500769ecc39de86ba /synapse/storage/__init__.py | |
parent | only need to loop if mau limiting is enabled (diff) | |
download | synapse-7931393495c76eef0af9b91c7904c88943197054.tar.xz |
make count_monthly_users async synapse/handlers/auth.py
Diffstat (limited to 'synapse/storage/__init__.py')
-rw-r--r-- | synapse/storage/__init__.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index 4747118ed7..f9682832ca 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -273,24 +273,24 @@ class DataStore(RoomMemberStore, RoomStore, This method should be refactored with count_daily_users - the only reason not to is waiting on definition of mau returns: - int: count of current monthly active users + defered: resolves to int """ + def _count_monthly_users(txn): + thirty_days_ago = int(self._clock.time_msec()) - (1000 * 60 * 60 * 24 * 30) + sql = """ + SELECT COALESCE(count(*), 0) FROM ( + SELECT user_id FROM user_ips + WHERE last_seen > ? + GROUP BY user_id + ) u + """ - thirty_days_ago = int(self._clock.time_msec()) - (1000 * 60 * 60 * 24 * 30) - sql = """ - SELECT COALESCE(count(*), 0) FROM ( - SELECT user_id FROM user_ips - WHERE last_seen > ? - GROUP BY user_id - ) u - """ - try: - txn = self.db_conn.cursor() txn.execute(sql, (thirty_days_ago,)) count, = txn.fetchone() + print "Count is %d" % (count,) return count - finally: - txn.close() + + return self.runInteraction("count_monthly_users", _count_monthly_users) def count_r30_users(self): """ |