changeset 59:8476f6028ee9

Session log: honor time window
author Lewin Bormann <lbo@spheniscida.de>
date Fri, 22 Jul 2022 21:36:43 -0700
parents 2e5b0e49efe1
children 5b91865546cf
files src/logsdb.rs
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/logsdb.rs	Fri Jul 22 21:34:34 2022 -0700
+++ b/src/logsdb.rs	Fri Jul 22 21:36:43 2022 -0700
@@ -414,6 +414,7 @@
         ctx: &LogsQueryContext,
         n: i64,
     ) -> 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#"
@@ -428,11 +429,15 @@
 FROM RequestLog
 JOIN Sessions ON (RequestLog.session = Sessions.id)
 LEFT JOIN RequestTags ON (RequestLog.id = RequestTags.requestid)
-WHERE Sessions.is_bot <= ?
+WHERE atime+? >= ? AND atime+? <= ? AND Sessions.is_bot <= ?
 GROUP BY Sessions.id
 ORDER BY Sessions.start DESC, RequestLog.atime DESC
 LIMIT ?;"#,
         )
+        .bind(tz_offset)
+        .bind(ctx.from.unix_timestamp())
+        .bind(tz_offset)
+        .bind(ctx.to.unix_timestamp())
         .bind(include_bots)
         .bind(n)
         .fetch(&mut *self.0)