diff --git a/server/src/api.rs b/server/src/api.rs index d3bb81c..a0fcb48 100644 --- a/server/src/api.rs +++ b/server/src/api.rs @@ -34,83 +34,3 @@ pub async fn instances( ); Ok(res) } - -pub async fn graph_csv_health( - State(ref db): State, - State(ref config): State>, -) -> Result { - let start = std::time::Instant::now(); - let healthy_data = health_check::HealthyAmount::fetch(db, None, None, None).await?; - let queried = std::time::Instant::now(); - let mut data = String::with_capacity(8 * healthy_data.len()); - - data.push_str("Date,Healthy,Dead\n"); - - for entry in healthy_data { - let time = Utc - .timestamp_opt(entry.time, 0) - .unwrap() - .format("%Y-%m-%dT%H:%M:%SZ"); - writeln!(&mut data, "{time},{},{}", entry.alive, entry.dead) - .map_err(|e| ServerError::CSV(e.to_string()))?; - } - let formatted = std::time::Instant::now(); - let query_time = queried - start; - let format_time = formatted - queried; - tracing::debug!(?query_time, ?format_time); - - let mut res = data.into_response(); - res.headers_mut() - .insert("content-type", HeaderValue::from_str("text/csv").unwrap()); - res.headers_mut().insert( - "cache-control", - HeaderValue::from_str(&format!("public, max-age={}", config.max_age)).unwrap(), - ); - res.headers_mut().insert( - "X-Robots-Tag", - HeaderValue::from_static("noindex, nofollow"), - ); - Ok(res) -} - -pub async fn graph_csv_stats( - State(ref db): State, - State(ref config): State>, -) -> Result { - let start = std::time::Instant::now(); - let healthy_data = instance_stats::StatsCSVEntry::fetch(db, None).await?; - let queried = std::time::Instant::now(); - let mut data = String::with_capacity(8 * healthy_data.len()); - - data.push_str("Date,Tokens AVG,Limited Tokens AVG,Requests AVG\n"); - - for entry in healthy_data { - let time = Utc - .timestamp_opt(entry.time, 0) - .unwrap() - .format("%Y-%m-%dT%H:%M:%SZ"); - writeln!( - &mut data, - "{time},{},{},{}", - entry.total_accs_avg, entry.limited_accs_avg, entry.total_requests_avg - ) - .map_err(|e| ServerError::CSV(e.to_string()))?; - } - let formatted = std::time::Instant::now(); - let query_time = queried - start; - let format_time = formatted - queried; - tracing::debug!(?query_time, ?format_time); - - let mut res = data.into_response(); - res.headers_mut() - .insert("content-type", HeaderValue::from_str("text/csv").unwrap()); - res.headers_mut().insert( - "cache-control", - HeaderValue::from_str(&format!("public, max-age={}", config.max_age)).unwrap(), - ); - res.headers_mut().insert( - "X-Robots-Tag", - HeaderValue::from_static("noindex, nofollow"), - ); - Ok(res) -} diff --git a/server/src/lib.rs b/server/src/lib.rs index 1399701..d48810e 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -148,8 +148,6 @@ pub async fn start( ServeDir::new("server/static").append_index_html_on_directories(false), ) .route("/api/v1/instances", get(api::instances)) - .route("/api/csv/health", get(api::graph_csv_health)) - .route("/api/csv/stats", get(api::graph_csv_stats)) .nest(ADMIN_OVERVIEW_URL, Router::new() .route("/", get(admin::overview)) .route("/instance/errors/:instance", get(admin::errors_view))