Mercurial > lbo > hg > analyrics
changeset 76:a58e1922e173
Fix some redirects and date calculations
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 09 Sep 2022 07:08:20 +0200 |
parents | d8ab669f71e5 |
children | fd0237049be0 |
files | Rocket.toml src/configdb.rs src/logsdb.rs src/main.rs |
diffstat | 4 files changed, 23 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Rocket.toml Wed Aug 17 18:06:41 2022 +0200 +++ b/Rocket.toml Fri Sep 09 07:08:20 2022 +0200 @@ -19,5 +19,5 @@ template_dir = "assets" asset_path = "assets/static" # deploy_path should end with a slash in order to work with templates, etc. -deploy_path = "/" +deploy_path = "" geodb_path = "/usr/share/GeoIP/GeoLite2-City.mmdb"
--- a/src/configdb.rs Wed Aug 17 18:06:41 2022 +0200 +++ b/src/configdb.rs Fri Sep 09 07:08:20 2022 +0200 @@ -21,7 +21,7 @@ #[derive(Default, Clone, Debug, FromRow)] pub struct UserRecord { pub name: String, - pub tz_offset: i32, + pub tz_offset: i64, } pub struct ConfigDBSession<'p, DB: sqlx::Database>(pub &'p mut sqlx::pool::PoolConnection<DB>);
--- a/src/logsdb.rs Wed Aug 17 18:06:41 2022 +0200 +++ b/src/logsdb.rs Fri Sep 09 07:08:20 2022 +0200 @@ -23,6 +23,7 @@ pub domain: Option<String>, pub from: OffsetDateTime, pub to: OffsetDateTime, + pub tz_offset: i64, pub include_bots: bool, } @@ -132,13 +133,14 @@ ctx: &LogsQueryContext, ) -> Result<(Vec<String>, Vec<u32>, Vec<u32>), Error> { let domain = ctx.domain.as_ref().map(String::as_str).unwrap_or("%"); + let tz_offset = ctx.tz_offset; let include_bots = if ctx.include_bots { 1 } else { 0 }; let mut results = sqlx::query( r#" -SELECT DATE(atime, 'unixepoch') AS rqdate, COUNT(requestlog.id) AS rqcount, sesscount +SELECT DATE(atime + ?, 'unixepoch') AS rqdate, COUNT(requestlog.id) AS rqcount, sesscount FROM requestlog JOIN ( - SELECT DATE(start, 'unixepoch') AS sessdate, COUNT(*) AS sesscount + SELECT DATE(start + ?, 'unixepoch') AS sessdate, COUNT(*) AS sesscount FROM sessions WHERE sessions.domain LIKE ? AND sessions.is_bot <= ? GROUP BY sessdate) AS sc ON (rqdate = sessdate) JOIN sessions ON (sessions.id = requestlog.session) @@ -146,6 +148,8 @@ GROUP BY rqdate ORDER BY rqdate ASC;"#, ) + .bind(tz_offset) + .bind(tz_offset) .bind(domain) .bind(include_bots) .bind(ctx.from.unix_timestamp()) @@ -181,16 +185,19 @@ &mut self, ctx: &LogsQueryContext, ) -> Result<Vec<(String, i64)>, Error> { + let tz_offset = ctx.tz_offset; let include_bots = if ctx.include_bots { 1 } else { 0 }; let result = sqlx::query( r#" SELECT origin_country, COUNT(*) AS count FROM sessions -WHERE start > ? AND start < ? AND domain LIKE ? AND is_bot <= ? +WHERE start+? > ? AND start+? < ? AND domain LIKE ? AND is_bot <= ? GROUP BY origin_country ORDER BY count DESC;"#, ) + .bind(tz_offset) .bind(ctx.from.unix_timestamp()) + .bind(tz_offset) .bind(ctx.to.unix_timestamp()) .bind(ctx.domain.as_ref().map(String::as_str).unwrap_or("%")) .bind(include_bots) @@ -208,6 +215,7 @@ ctx: &LogsQueryContext, n: i64, ) -> Result<Vec<(String, i64)>, Error> { + let tz_offset = ctx.tz_offset; let include_bots = if ctx.include_bots { 1 } else { 0 }; let result = sqlx::query( r#" @@ -245,19 +253,20 @@ &mut self, ctx: &LogsQueryContext, ) -> Result<Vec<(String, f32)>, Error> { + let tz_offset = ctx.tz_offset; let include_bots = if ctx.include_bots { 1 } else { 0 }; let result = sqlx::query( r#" SELECT d, CAST(nreq AS REAL)/nses FROM - (SELECT DATE(atime, 'unixepoch') AS d, + (SELECT DATE(atime+?, 'unixepoch') AS d, COUNT(*) AS nreq FROM RequestLog JOIN Sessions ON (Sessions.id = RequestLog.session) WHERE atime > ? AND atime < ? AND RequestLog.domain LIKE ? AND is_bot <= ? GROUP BY d) JOIN - (SELECT DATE(start, 'unixepoch') AS d2, + (SELECT DATE(start+?, 'unixepoch') AS d2, COUNT(*) as nses FROM Sessions WHERE start > ? AND start < ? AND Sessions.domain LIKE ? AND is_bot <= ? @@ -265,10 +274,12 @@ ON (d = d2) ORDER BY d ASC"#, ) + .bind(tz_offset) .bind(ctx.from.unix_timestamp()) .bind(ctx.to.unix_timestamp()) .bind(ctx.domain.as_ref().map(String::as_str).unwrap_or("%")) .bind(include_bots) + .bind(tz_offset) .bind(ctx.from.unix_timestamp()) .bind(ctx.to.unix_timestamp()) .bind(ctx.domain.as_ref().map(String::as_str).unwrap_or("%")) @@ -297,6 +308,7 @@ &mut self, ctx: &LogsQueryContext, ) -> Result<Vec<(String, i64)>, Error> { + let tz_offset = ctx.tz_offset; let include_bots = if ctx.include_bots { 1 } else { 0 }; let result = sqlx::query( r#" @@ -358,6 +370,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 }; // Check later if this query possibly has bad scaling behavior due to no restrictions on // requesttags query.
--- a/src/main.rs Wed Aug 17 18:06:41 2022 +0200 +++ b/src/main.rs Fri Sep 09 07:08:20 2022 +0200 @@ -67,7 +67,7 @@ } if let Some(cookie) = cookies.get_private(USER_ID_COOKIE_KEY) { Ok(LoginResponse::LoggedInAlready { - redirect: Redirect::to(cc.deploy_path.clone()), + redirect: Redirect::to(format!("{}/", cc.deploy_path.clone())), }) } else { Ok(LoginResponse::Ok { @@ -82,7 +82,7 @@ cookies.remove_private(cookie); } Flash::success( - Redirect::to(cc.deploy_path.clone()), + Redirect::to(format!("{}/", cc.deploy_path.clone())), format!("Logged out. Goodbye!"), ) } @@ -247,6 +247,7 @@ domain: domain.clone(), from: begin, to: end, + tz_offset, include_bots: includebots, };