Fix user_daily_visits to not have duplicate rows for UA. (#8654)

* Fix user_daily_visits to not have duplicate rows for UA.

Fixes #8641.

* Newsfile

* Fix typo.

Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
This commit is contained in:
Erik Johnston 2020-10-26 13:16:32 +00:00 committed by GitHub
parent 5065048110
commit 437a99fb99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

1
changelog.d/8654.bugfix Normal file
View file

@ -0,0 +1 @@
Fix `user_daily_visits` to not have duplicate rows for UA. Broke in v1.22.0rc1.

View file

@ -282,9 +282,10 @@ class ServerMetricsStore(EventPushActionsWorkerStore, SQLBaseStore):
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 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 = """
INSERT INTO user_daily_visits (user_id, device_id, timestamp, user_agent)
@ -299,7 +300,7 @@ class ServerMetricsStore(EventPushActionsWorkerStore, SQLBaseStore):
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