Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

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

Merged
merged 3 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8654.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `user_daily_visits` to not have duplicate rows for UA. Broke in v1.22.0rc1.
9 changes: 5 additions & 4 deletions synapse/storage/databases/main/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
clokep marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Expand All @@ -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
Expand Down