mirror of
https://github.com/4cuck/nitter-status.git
synced 2026-10-26 00:52:25 +00:00
cleanup
This commit is contained in:
1 parent
5c1b198bbb
commit
2ab7e1a6fc
3 files changed
+4
-33
No files matched your search
@@ -25,19 +25,6 @@ pub struct HostStats {
|
|||||||
pub struct LatestCheck {
|
pub struct LatestCheck {
|
||||||
host: i32,
|
host: i32,
|
||||||
healthy: bool,
|
healthy: bool,
|
||||||
resp_time: Option<i32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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)]
|
#[derive(Debug, Default)]
|
||||||
@@ -206,22 +193,6 @@ impl Scanner {
|
|||||||
Ok(map)
|
Ok(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn query_ping_avg(&self, age: DateTimeUtc) -> Result<Vec<PingAvg>> {
|
|
||||||
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<Vec<LatestCheck>> {
|
async fn query_latest_check(&self) -> Result<Vec<LatestCheck>> {
|
||||||
let upte_checks = LatestCheck::find_by_statement(Statement::from_sql_and_values(
|
let upte_checks = LatestCheck::find_by_statement(Statement::from_sql_and_values(
|
||||||
DbBackend::Sqlite,
|
DbBackend::Sqlite,
|
||||||
@@ -230,7 +201,7 @@ impl Scanner {
|
|||||||
SELECT u.host,MAX(u.time) as time FROM update_check u
|
SELECT u.host,MAX(u.time) as time FROM update_check u
|
||||||
GROUP BY u.host
|
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 host h ON h.id = u.host
|
||||||
JOIN latest l ON l.host = u.host AND l.time = u.time
|
JOIN latest l ON l.host = u.host AND l.time = u.time
|
||||||
WHERE h.enabled = true
|
WHERE h.enabled = true
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use about_parser::AboutParser;
|
use about_parser::AboutParser;
|
||||||
use chrono::{Utc, Duration};
|
use chrono::Utc;
|
||||||
use entities::{
|
use entities::{
|
||||||
host,
|
host,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
|||||||
+2
-2
@@ -55,7 +55,7 @@ async fn _main() -> miette::Result<()> {
|
|||||||
|
|
||||||
let server_config = read_server_config(scanner_config.instance_check_interval.as_secs() as _)?;
|
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");
|
tracing::info!("migrating db");
|
||||||
migration::Migrator::up(&pool, None)
|
migration::Migrator::up(&pool, None)
|
||||||
@@ -120,7 +120,7 @@ fn read_scanner_cfg() -> miette::Result<ScannerConfig> {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn test_init(db: &DatabaseConnection, conf: &server::Config) -> miette::Result<()> {
|
async fn test_init(db: &DatabaseConnection) -> miette::Result<()> {
|
||||||
let res = db
|
let res = db
|
||||||
.query_one(sea_orm::Statement::from_string(
|
.query_one(sea_orm::Statement::from_string(
|
||||||
DatabaseBackend::Postgres,
|
DatabaseBackend::Postgres,
|
||||||
|
|||||||
Reference in new issue
Block a user