Mercurial > lbo > hg > analyrics
changeset 64:3bcab50dcca5
Fix recent sessions query
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 25 Jul 2022 09:21:26 -0700 |
parents | b0ad92c96f60 |
children | 2715ed801bb1 |
files | src/logsdb.rs |
diffstat | 1 files changed, 20 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/logsdb.rs Mon Jul 25 09:05:45 2022 -0700 +++ b/src/logsdb.rs Mon Jul 25 09:21:26 2022 -0700 @@ -382,24 +382,29 @@ ) -> Result<Vec<RecentSessionsRow>, Error> { let tz_offset = ctx.tz_offset; let include_bots = if ctx.include_bots { 1 } else { 0 }; - let result = sqlx::query( - r#" -SELECT Sessions.start AS start, - Sessions.last-Sessions.start AS duration, - COUNT(*) AS count, - RequestLog.Refer AS refer, - Sessions.origin_country AS origin_country, - Sessions.origin_city AS origin_city, + // Check later if this query possibly has bad scaling behavior due to no restrictions on + // requesttags query. + let result = sqlx::query(r#" +SELECT Sessions.start AS start, + Sessions.last-Sessions.start AS duration, + COUNT(RequestLog.id) AS count, + RequestLog.Refer AS refer, + Sessions.origin_country AS origin_country, + Sessions.origin_city AS origin_city, RequestLog.ua AS ua, - GROUP_CONCAT(IIF(value, PRINTF("%s=%s", IIF(key, key, ""), value), key)) AS alltags -FROM RequestLog -JOIN Sessions ON (RequestLog.session = Sessions.id) -LEFT JOIN RequestTags ON (RequestLog.id = RequestTags.requestid) + tagstring AS alltags +FROM RequestLog +JOIN Sessions ON (RequestLog.session = Sessions.id) +LEFT JOIN + (SELECT + requestid, + GROUP_CONCAT(IIF(value, PRINTF("%s=%s", IIF(key, key, ""), value), key)) AS tagstring + FROM RequestTags GROUP BY requestid) AS AccumTags + ON (RequestLog.id = AccumTags.requestid) WHERE atime+? >= ? AND atime+? <= ? AND Sessions.is_bot <= ? -GROUP BY Sessions.id +GROUP BY Sessions.id ORDER BY Sessions.start DESC, RequestLog.atime DESC -LIMIT ?;"#, - ) +LIMIT 10;"#) .bind(tz_offset) .bind(ctx.from.unix_timestamp()) .bind(tz_offset)