From 2ab7e1a6fcbaf8eacabe7ccc020feddd6cf72c86 Mon Sep 17 00:00:00 2001 From: 4cuck <40539855+4cuck@users.noreply.github.com> Date: Fri, 28 Jul 2023 17:58:25 +0200 Subject: [PATCH] cleanup --- scanner/src/cache_update.rs | 31 +------------------------------ scanner/src/lib.rs | 2 +- src/main.rs | 4 ++-- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/scanner/src/cache_update.rs b/scanner/src/cache_update.rs index 5edc59b..aeaddb3 100644 --- a/scanner/src/cache_update.rs +++ b/scanner/src/cache_update.rs @@ -25,19 +25,6 @@ pub struct HostStats { pub struct LatestCheck { host: i32, healthy: bool, - resp_time: Option, -} - -#[derive(Debug, FromQueryResult, Default)] -pub struct PingAvg { - host: i32, - ping_avg: i32, -} - -#[derive(Debug, FromQueryResult, Default)] -pub struct LastPingsQuery { - host: i32, - ping: i32, } #[derive(Debug, Default)] @@ -206,22 +193,6 @@ impl Scanner { Ok(map) } - async fn query_ping_avg(&self, age: DateTimeUtc) -> Result> { - let upte_checks = PingAvg::find_by_statement(Statement::from_sql_and_values( - DbBackend::Sqlite, - r#" - SELECT u.host,CAST(AVG(u.resp_time) AS INT) as ping_avg FROM update_check u - JOIN host h ON h.id = u.host - WHERE h.enabled = true AND u.healthy = true AND u.time >= $1 - GROUP BY u.host - "#, - [age.into()], - )) - .all(&self.inner.db) - .await?; - Ok(upte_checks) - } - async fn query_latest_check(&self) -> Result> { let upte_checks = LatestCheck::find_by_statement(Statement::from_sql_and_values( DbBackend::Sqlite, @@ -230,7 +201,7 @@ impl Scanner { SELECT u.host,MAX(u.time) as time FROM update_check u GROUP BY u.host ) - SELECT u.host,u.time,resp_time,healthy FROM update_check u + SELECT u.host,u.time,healthy FROM update_check u JOIN host h ON h.id = u.host JOIN latest l ON l.host = u.host AND l.time = u.time WHERE h.enabled = true diff --git a/scanner/src/lib.rs b/scanner/src/lib.rs index 24a4640..437a3c2 100644 --- a/scanner/src/lib.rs +++ b/scanner/src/lib.rs @@ -5,7 +5,7 @@ use std::{ }; use about_parser::AboutParser; -use chrono::{Utc, Duration}; +use chrono::Utc; use entities::{ host, prelude::*, diff --git a/src/main.rs b/src/main.rs index 8496021..50f710a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,7 @@ async fn _main() -> miette::Result<()> { let server_config = read_server_config(scanner_config.instance_check_interval.as_secs() as _)?; - test_init(&pool, &server_config).await?; + test_init(&pool).await?; tracing::info!("migrating db"); migration::Migrator::up(&pool, None) @@ -120,7 +120,7 @@ fn read_scanner_cfg() -> miette::Result { })) } -async fn test_init(db: &DatabaseConnection, conf: &server::Config) -> miette::Result<()> { +async fn test_init(db: &DatabaseConnection) -> miette::Result<()> { let res = db .query_one(sea_orm::Statement::from_string( DatabaseBackend::Postgres,