mirror of
https://github.com/matrix-org/dendrite
synced 2024-11-10 15:14:36 +00:00
Update table names for user API stats table
This commit is contained in:
parent
530fd488a9
commit
42f35a57ac
2 changed files with 14 additions and 14 deletions
|
@ -30,7 +30,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const userDailyVisitsSchema = `
|
const userDailyVisitsSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS user_daily_visits (
|
CREATE TABLE IF NOT EXISTS userapi_daily_visits (
|
||||||
localpart TEXT NOT NULL,
|
localpart TEXT NOT NULL,
|
||||||
device_id TEXT NOT NULL,
|
device_id TEXT NOT NULL,
|
||||||
timestamp BIGINT NOT NULL,
|
timestamp BIGINT NOT NULL,
|
||||||
|
@ -38,9 +38,9 @@ CREATE TABLE IF NOT EXISTS user_daily_visits (
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Device IDs and timestamp must be unique for a given user per day
|
-- Device IDs and timestamp must be unique for a given user per day
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS localpart_device_timestamp_idx ON user_daily_visits(localpart, device_id, timestamp);
|
CREATE UNIQUE INDEX IF NOT EXISTS userapi_daily_visits_localpart_device_timestamp_idx ON userapi_daily_visits(localpart, device_id, timestamp);
|
||||||
CREATE INDEX IF NOT EXISTS timestamp_idx ON user_daily_visits(timestamp);
|
CREATE INDEX IF NOT EXISTS userapi_daily_visits_timestamp_idx ON userapi_daily_visits(timestamp);
|
||||||
CREATE INDEX IF NOT EXISTS localpart_timestamp_idx ON user_daily_visits(localpart, timestamp);
|
CREATE INDEX IF NOT EXISTS userapi_daily_visits_localpart_timestamp_idx ON userapi_daily_visits(localpart, timestamp);
|
||||||
`
|
`
|
||||||
|
|
||||||
const countUsersLastSeenAfterSQL = "" +
|
const countUsersLastSeenAfterSQL = "" +
|
||||||
|
@ -112,7 +112,7 @@ FROM
|
||||||
WHEN LOWER(user_agent) LIKE '%%mozilla%%' OR LOWER(user_agent) LIKE '%%gecko%%' THEN 'web'
|
WHEN LOWER(user_agent) LIKE '%%mozilla%%' OR LOWER(user_agent) LIKE '%%gecko%%' THEN 'web'
|
||||||
ELSE 'unknown'
|
ELSE 'unknown'
|
||||||
END as client_type
|
END as client_type
|
||||||
FROM user_daily_visits
|
FROM userapi_daily_visits
|
||||||
WHERE timestamp > $1 AND timestamp < $2
|
WHERE timestamp > $1 AND timestamp < $2
|
||||||
GROUP BY localpart, client_type
|
GROUP BY localpart, client_type
|
||||||
HAVING max(timestamp) - min(timestamp) > $3
|
HAVING max(timestamp) - min(timestamp) > $3
|
||||||
|
@ -141,11 +141,11 @@ SELECT user_type, COUNT(*) AS count FROM (
|
||||||
|
|
||||||
// account_type 1 = users; 3 = admins
|
// account_type 1 = users; 3 = admins
|
||||||
const updateUserDailyVisitsSQL = `
|
const updateUserDailyVisitsSQL = `
|
||||||
INSERT INTO user_daily_visits(localpart, device_id, timestamp, user_agent)
|
INSERT INTO userapi_daily_visits(localpart, device_id, timestamp, user_agent)
|
||||||
SELECT u.localpart, u.device_id, $1, MAX(u.user_agent)
|
SELECT u.localpart, u.device_id, $1, MAX(u.user_agent)
|
||||||
FROM device_devices AS u
|
FROM device_devices AS u
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT localpart, device_id, timestamp FROM user_daily_visits
|
SELECT localpart, device_id, timestamp FROM userapi_daily_visits
|
||||||
WHERE timestamp = $1
|
WHERE timestamp = $1
|
||||||
) udv
|
) udv
|
||||||
ON u.localpart = udv.localpart AND u.device_id = udv.device_id
|
ON u.localpart = udv.localpart AND u.device_id = udv.device_id
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const userDailyVisitsSchema = `
|
const userDailyVisitsSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS user_daily_visits (
|
CREATE TABLE IF NOT EXISTS userapi_daily_visits (
|
||||||
localpart TEXT NOT NULL,
|
localpart TEXT NOT NULL,
|
||||||
device_id TEXT NOT NULL,
|
device_id TEXT NOT NULL,
|
||||||
timestamp BIGINT NOT NULL,
|
timestamp BIGINT NOT NULL,
|
||||||
|
@ -38,9 +38,9 @@ CREATE TABLE IF NOT EXISTS user_daily_visits (
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Device IDs and timestamp must be unique for a given user per day
|
-- Device IDs and timestamp must be unique for a given user per day
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS localpart_device_timestamp_idx ON user_daily_visits(localpart, device_id, timestamp);
|
CREATE UNIQUE INDEX IF NOT EXISTS userapi_daily_visits_localpart_device_timestamp_idx ON userapi_daily_visits(localpart, device_id, timestamp);
|
||||||
CREATE INDEX IF NOT EXISTS timestamp_idx ON user_daily_visits(timestamp);
|
CREATE INDEX IF NOT EXISTS userapi_daily_visits_timestamp_idx ON userapi_daily_visits(timestamp);
|
||||||
CREATE INDEX IF NOT EXISTS localpart_timestamp_idx ON user_daily_visits(localpart, timestamp);
|
CREATE INDEX IF NOT EXISTS userapi_daily_visits_localpart_timestamp_idx ON userapi_daily_visits(localpart, timestamp);
|
||||||
`
|
`
|
||||||
|
|
||||||
const countUsersLastSeenAfterSQL = "" +
|
const countUsersLastSeenAfterSQL = "" +
|
||||||
|
@ -116,7 +116,7 @@ FROM
|
||||||
WHEN LOWER(user_agent) LIKE '%%mozilla%%' OR LOWER(user_agent) LIKE '%%gecko%%' THEN 'web'
|
WHEN LOWER(user_agent) LIKE '%%mozilla%%' OR LOWER(user_agent) LIKE '%%gecko%%' THEN 'web'
|
||||||
ELSE 'unknown'
|
ELSE 'unknown'
|
||||||
END as client_type
|
END as client_type
|
||||||
FROM user_daily_visits
|
FROM userapi_daily_visits
|
||||||
WHERE timestamp > $1 AND timestamp < $2
|
WHERE timestamp > $1 AND timestamp < $2
|
||||||
GROUP BY localpart, client_type
|
GROUP BY localpart, client_type
|
||||||
HAVING max(timestamp) - min(timestamp) > $3
|
HAVING max(timestamp) - min(timestamp) > $3
|
||||||
|
@ -145,11 +145,11 @@ SELECT user_type, COUNT(*) AS count FROM (
|
||||||
|
|
||||||
// account_type 1 = users; 3 = admins
|
// account_type 1 = users; 3 = admins
|
||||||
const updateUserDailyVisitsSQL = `
|
const updateUserDailyVisitsSQL = `
|
||||||
INSERT INTO user_daily_visits(localpart, device_id, timestamp, user_agent)
|
INSERT INTO userapi_daily_visits(localpart, device_id, timestamp, user_agent)
|
||||||
SELECT u.localpart, u.device_id, $1, MAX(u.user_agent)
|
SELECT u.localpart, u.device_id, $1, MAX(u.user_agent)
|
||||||
FROM device_devices AS u
|
FROM device_devices AS u
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT localpart, device_id, timestamp FROM user_daily_visits
|
SELECT localpart, device_id, timestamp FROM userapi_daily_visits
|
||||||
WHERE timestamp = $1
|
WHERE timestamp = $1
|
||||||
) udv
|
) udv
|
||||||
ON u.localpart = udv.localpart AND u.device_id = udv.device_id
|
ON u.localpart = udv.localpart AND u.device_id = udv.device_id
|
||||||
|
|
Loading…
Reference in a new issue