Add user agent to user_daily_visits table.

pull/8503/head
Neil Johnson 2020-10-08 18:23:13 +01:00
parent a83392f674
commit 9cbd459945
3 changed files with 23 additions and 3 deletions

View File

@ -282,8 +282,8 @@ class ServerMetricsStore(EventPushActionsWorkerStore, SQLBaseStore):
now = self._clock.time_msec()
sql = """
INSERT INTO user_daily_visits (user_id, device_id, timestamp)
SELECT u.user_id, u.device_id, ?
INSERT INTO user_daily_visits (user_id, device_id, timestamp, user_agent)
SELECT u.user_id, u.device_id, ?, u.user_agent
FROM user_ips AS u
LEFT JOIN (
SELECT user_id, device_id, timestamp FROM user_daily_visits
@ -314,11 +314,13 @@ class ServerMetricsStore(EventPushActionsWorkerStore, SQLBaseStore):
today_start,
),
)
self._last_user_visit_update = today_start
txn.execute(
sql, (today_start, today_start, self._last_user_visit_update, now)
)
logger.info('today start %s last_user_visit %s now %s' % (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

View File

@ -0,0 +1,18 @@
/* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-- Add new column to user_daily_visits to track user agent
ALTER TABLE user_daily_visits
ADD COLUMN user_agent TEXT;

View File

@ -37,7 +37,7 @@ logger = logging.getLogger(__name__)
# XXX: If you're about to bump this to 59 (or higher) please create an update
# that drops the unused `cache_invalidation_stream` table, as per #7436!
# XXX: Also add an update to drop `account_data_max_stream_id` as per #7656!
SCHEMA_VERSION = 58
SCHEMA_VERSION = 59
dir_path = os.path.abspath(os.path.dirname(__file__))