summary refs log tree commit diff
path: root/synapse/storage/__init__.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2017-06-15 12:46:23 +0100
committerGitHub <noreply@github.com>2017-06-15 12:46:23 +0100
commit052c5d19d5f8ce3b73820497cf58d293b266f088 (patch)
tree35a3c30e12ed8728a9373f3ce4b865ad52dc8daa /synapse/storage/__init__.py
parentadd notes on running out of FDs (diff)
parentTypo (diff)
downloadsynapse-052c5d19d5f8ce3b73820497cf58d293b266f088.tar.xz
Merge pull request #2281 from matrix-org/erikj/phone_home_stats
Fix phone home stats
Diffstat (limited to 'synapse/storage/__init__.py')
-rw-r--r--synapse/storage/__init__.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 5e72985cda..f119c5a758 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -246,7 +246,7 @@ class DataStore(RoomMemberStore, RoomStore,
         cur.close()
 
         self.find_stream_orderings_looping_call = self._clock.looping_call(
-            self._find_stream_orderings_for_times, 60 * 60 * 1000
+            self._find_stream_orderings_for_times, 10 * 60 * 1000
         )
 
         self._stream_order_on_start = self.get_room_max_stream_ordering()
@@ -287,17 +287,19 @@ class DataStore(RoomMemberStore, RoomStore,
         Counts the number of users who used this homeserver in the last 24 hours.
         """
         def _count_users(txn):
-            txn.execute(
-                "SELECT COUNT(DISTINCT user_id) AS users"
-                " FROM user_ips"
-                " WHERE last_seen > ?",
-                # This is close enough to a day for our purposes.
-                (int(self._clock.time_msec()) - (1000 * 60 * 60 * 24),)
-            )
-            rows = self.cursor_to_dict(txn)
-            if rows:
-                return rows[0]["users"]
-            return 0
+            yesterday = int(self._clock.time_msec()) - (1000 * 60 * 60 * 24),
+
+            sql = """
+                SELECT COALESCE(count(*), 0) FROM (
+                    SELECT user_id FROM user_ips
+                    WHERE last_seen > ?
+                    GROUP BY user_id
+                ) u
+            """
+
+            txn.execute(sql, (yesterday,))
+            count, = txn.fetchone()
+            return count
 
         ret = yield self.runInteraction("count_users", _count_users)
         defer.returnValue(ret)