From b4a4d6bc609e2c2d1b4ffab6f57b325b95d6fee9 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 6 Jul 2021 14:20:54 +0100 Subject: [PATCH 1/4] Use fake time in tests in _get_start_of_day. --- synapse/storage/databases/main/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/metrics.py b/synapse/storage/databases/main/metrics.py index c3f551d37756..be916d1fcb3b 100644 --- a/synapse/storage/databases/main/metrics.py +++ b/synapse/storage/databases/main/metrics.py @@ -320,7 +320,7 @@ def _get_start_of_day(self): """ Returns millisecond unixtime for start of UTC day. """ - now = time.gmtime() + now = time.gmtime(self.hs.get_clock().time()) today_start = calendar.timegm((now.tm_year, now.tm_mon, now.tm_mday, 0, 0, 0)) return today_start * 1000 From a96d3091c616baccdc45e99e63bcca3872dcd741 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 6 Jul 2021 14:21:26 +0100 Subject: [PATCH 2/4] Change the inequality of last_seen in user_daily_visits --- synapse/storage/databases/main/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/metrics.py b/synapse/storage/databases/main/metrics.py index be916d1fcb3b..90225d503c1a 100644 --- a/synapse/storage/databases/main/metrics.py +++ b/synapse/storage/databases/main/metrics.py @@ -352,7 +352,7 @@ def _generate_user_daily_visits(txn): ) udv ON u.user_id = udv.user_id AND u.device_id=udv.device_id INNER JOIN users ON users.name=u.user_id - WHERE last_seen > ? AND last_seen <= ? + WHERE ? <= last_seen AND last_seen < ? AND udv.timestamp IS NULL AND users.is_guest=0 AND users.appservice_id IS NULL GROUP BY u.user_id, u.device_id From 148972f5535c23ed9d803b245ad64e8d859906cb Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 6 Jul 2021 14:22:42 +0100 Subject: [PATCH 3/4] Newsfile --- changelog.d/10324.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/10324.misc diff --git a/changelog.d/10324.misc b/changelog.d/10324.misc new file mode 100644 index 000000000000..3c3ee6d6fc0b --- /dev/null +++ b/changelog.d/10324.misc @@ -0,0 +1 @@ +Minor change to the code that populates `user_daily_visits`. From 6552cb0bfc106c555728f39f1e693ee54874025b Mon Sep 17 00:00:00 2001 From: reivilibre <38398653+reivilibre@users.noreply.github.com> Date: Thu, 8 Jul 2021 09:35:46 +0100 Subject: [PATCH 4/4] Use _clock directly Co-authored-by: Erik Johnston --- synapse/storage/databases/main/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/metrics.py b/synapse/storage/databases/main/metrics.py index 90225d503c1a..e3a544d9b25f 100644 --- a/synapse/storage/databases/main/metrics.py +++ b/synapse/storage/databases/main/metrics.py @@ -320,7 +320,7 @@ def _get_start_of_day(self): """ Returns millisecond unixtime for start of UTC day. """ - now = time.gmtime(self.hs.get_clock().time()) + now = time.gmtime(self._clock.time()) today_start = calendar.timegm((now.tm_year, now.tm_mon, now.tm_mday, 0, 0, 0)) return today_start * 1000