From 8db622fe31c6e9f0aaa0a082800a1aa996427caa Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 26 Oct 2020 10:13:53 +0000 Subject: [PATCH 1/3] Fix user_daily_visits to not have duplicate rows for UA. Fixes #8641. --- synapse/storage/databases/main/metrics.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/synapse/storage/databases/main/metrics.py b/synapse/storage/databases/main/metrics.py index 79b01d16f9d5..bdc0b9154fc1 100644 --- a/synapse/storage/databases/main/metrics.py +++ b/synapse/storage/databases/main/metrics.py @@ -282,9 +282,10 @@ def _generate_user_daily_visits(txn): now = self._clock.time_msec() # A note on user_agent. Technically a given device can have multiple - # user agents, so we need to decide which one to pick. We could have handled this - # in number of ways, but given that we don't _that_ much have gone for MAX() - # For more details of the other options considered see + # user agents, so we need to decide which one to pick. We could have + # handled this in number of ways, but given that we don't care + # _that_ much wehave gone for MAX(). For more details of the other + # options considered see # https://github.com/matrix-org/synapse/pull/8503#discussion_r502306111 sql = """ INSERT INTO user_daily_visits (user_id, device_id, timestamp, user_agent) @@ -299,7 +300,7 @@ def _generate_user_daily_visits(txn): 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, u.user_agent + GROUP BY u.user_id, u.device_id """ # This means that the day has rolled over but there could still From 8e1db5e3f822ba30ef64acbe4f49f3ffdd5c2d10 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 26 Oct 2020 10:17:51 +0000 Subject: [PATCH 2/3] Newsfile --- changelog.d/8654.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/8654.bugfix diff --git a/changelog.d/8654.bugfix b/changelog.d/8654.bugfix new file mode 100644 index 000000000000..91d3265b7f82 --- /dev/null +++ b/changelog.d/8654.bugfix @@ -0,0 +1 @@ +Fix `user_daily_visits` to not have duplicate rows for UA. Broke in v1.22.0rc1. From a69dab34cc8256cd5b5afe4a8fc2c236356d3243 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 26 Oct 2020 08:35:24 -0400 Subject: [PATCH 3/3] Fix typo. --- 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 bdc0b9154fc1..ab18cc4d79be 100644 --- a/synapse/storage/databases/main/metrics.py +++ b/synapse/storage/databases/main/metrics.py @@ -284,7 +284,7 @@ def _generate_user_daily_visits(txn): # A note on user_agent. Technically a given device can have multiple # user agents, so we need to decide which one to pick. We could have # handled this in number of ways, but given that we don't care - # _that_ much wehave gone for MAX(). For more details of the other + # _that_ much we have gone for MAX(). For more details of the other # options considered see # https://github.com/matrix-org/synapse/pull/8503#discussion_r502306111 sql = """