summary refs log tree commit diff
path: root/synapse/storage/__init__.py
diff options
context:
space:
mode:
authorNeil Johnson <neil@fragile.org.uk>2018-05-16 09:46:43 +0100
committerNeil Johnson <neil@fragile.org.uk>2018-05-16 09:46:43 +0100
commit31c2502ca8d74797f1eae553690830b8c132aed9 (patch)
tree2862fba514f4ed3a47e9b05a4780dda932598e05 /synapse/storage/__init__.py
parentpep8 (diff)
downloadsynapse-31c2502ca8d74797f1eae553690830b8c132aed9.tar.xz
style and further contraining query
Diffstat (limited to 'synapse/storage/__init__.py')
-rw-r--r--synapse/storage/__init__.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 52f176a03c..6f324e075f 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -368,6 +368,7 @@ class DataStore(RoomMemberStore, RoomStore,
             logger.info("Calling _generate_user_daily_visits")
             today_start = self._get_start_of_day()
             a_day_in_milliseconds = 24 * 60 * 60 * 1000
+            now = self.clock.time_msec()
 
             sql = """
                 INSERT INTO user_daily_visits (user_id, device_id, timestamp)
@@ -386,23 +387,26 @@ class DataStore(RoomMemberStore, RoomStore,
             # where if the user logs in at 23:59 and overwrites their
             # last_seen at 00:01 then they will not be counted in the
             # previous day's stats - it is important that the query is run
-            # to minimise this case.
+            # often to minimise this case.
             if today_start > self._last_user_visit_update:
                 yesterday_start = today_start - a_day_in_milliseconds
-                txn.execute(sql, (yesterday_start, yesterday_start,
-                                  self._last_user_visit_update, today_start))
+                txn.execute(sql, (
+                    yesterday_start, yesterday_start,
+                    self._last_user_visit_update, today_start
+                ))
                 self._last_user_visit_update = today_start
 
-            txn.execute(sql, (today_start, today_start,
-                              self._last_user_visit_update,
-                              today_start + a_day_in_milliseconds))
+            txn.execute(sql, (
+                today_start, today_start,
+                self._last_user_visit_update,
+                now
+            ))
             # Update _last_user_visit_update to now. The reason to do this
             # rather just clamping to the beginning of the day is to limit
             # the size of the join - meaning that the query can be run more
             # frequently
 
-            now = datetime.datetime.utcnow()
-            self._last_user_visit_update = int(time.mktime(now.timetuple())) * 1000
+            self._last_user_visit_update = now
 
         return self.runInteraction("generate_user_daily_visits",
                                    _generate_user_daily_visits)