summary refs log tree commit diff
diff options
context:
space:
mode:
authorNeil Johnson <neil@matrix.org>2019-01-04 16:33:39 +0000
committerNeil Johnson <neil@matrix.org>2019-01-04 16:33:39 +0000
commit2af5440cecfdc9eb56855bdb43809d671ae834ab (patch)
tree218a0b067ce823eec58a083b2bbe5aeb8027ac30
parentfix NPE in /messages by checking if all events were filtered out (#4330) (diff)
downloadsynapse-github/neilj/add_ua_to_udv_table.tar.xz
store ua in user_daily_visits table and make population optional github/neilj/add_ua_to_udv_table neilj/add_ua_to_udv_table
-rwxr-xr-xsynapse/app/homeserver.py10
-rw-r--r--synapse/config/server.py3
-rw-r--r--synapse/storage/__init__.py4
3 files changed, 10 insertions, 7 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index f3ac3d19f0..ffaa0ae94a 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -500,11 +500,11 @@ def run(hs):
             "generate_user_daily_visits",
             hs.get_datastore().generate_user_daily_visits,
         )
-
-    # Rather than update on per session basis, batch up the requests.
-    # If you increase the loop period, the accuracy of user_daily_visits
-    # table will decrease
-    clock.looping_call(generate_user_daily_visit_stats, 5 * 60 * 1000)
+    if hs.config.store_user_daily_visits:
+        # Rather than update on per session basis, batch up the requests.
+        # If you increase the loop period, the accuracy of user_daily_visits
+        # table will decrease
+        clock.looping_call(generate_user_daily_visit_stats, 5 * 60 * 1000)
 
     # monthly active user limiting functionality
     def reap_monthly_active_users():
diff --git a/synapse/config/server.py b/synapse/config/server.py
index 120c2b81fc..809f75cae4 100644
--- a/synapse/config/server.py
+++ b/synapse/config/server.py
@@ -97,6 +97,9 @@ class ServerConfig(Config):
         self.hs_disabled_message = config.get("hs_disabled_message", "")
         self.hs_disabled_limit_type = config.get("hs_disabled_limit_type", "")
 
+        # User stats
+        self.store_user_daily_visits = config.get("store_user_daily_visits", False)
+
         # Admin uri to direct users at should their instance become blocked
         # due to resource constraints
         self.admin_contact = config.get("admin_contact", None)
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 24329879e5..ce9f9d0094 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -372,8 +372,8 @@ class DataStore(RoomMemberStore, RoomStore,
             now = self.clock.time_msec()
 
             sql = """
-                INSERT INTO user_daily_visits (user_id, device_id, timestamp)
-                    SELECT u.user_id, u.device_id, ?
+                INSERT INTO user_daily_visits (user_id, device_id, timestamp, user_agent)
+                    SELECT u.user_id, u.device_id, ?, u.user_agent
                     FROM user_ips AS u
                     LEFT JOIN (
                       SELECT user_id, device_id, timestamp FROM user_daily_visits