at protocol indexer with flexible filtering, xrpc queries, and a cursor-backed event stream, built on fjall
at-protocol atproto indexer rust fjall
at 8990a2ff5651c71cb6fa29aa3c44fa4212b6a4f6 35 lines 967 B view raw
1use crate::api::AppState; 2use axum::{Json, extract::State, response::Result}; 3use serde::Serialize; 4use std::{collections::BTreeMap, sync::Arc}; 5 6#[derive(Serialize)] 7pub struct StatsResponse { 8 pub counts: BTreeMap<&'static str, u64>, 9} 10 11pub async fn get_stats(State(state): State<Arc<AppState>>) -> Result<Json<StatsResponse>> { 12 let db = &state.db; 13 14 let mut counts: BTreeMap<&'static str, u64> = futures::future::join_all( 15 [ 16 "repos", 17 "pending", 18 "resync", 19 "records", 20 "blocks", 21 "error_ratelimited", 22 "error_transport", 23 "error_generic", 24 ] 25 .into_iter() 26 .map(|name| async move { (name, db.get_count(name).await) }), 27 ) 28 .await 29 .into_iter() 30 .collect(); 31 // this should be accurate since we dont remove events 32 counts.insert("events", db.events.approximate_len() as u64); 33 34 Ok(Json(StatsResponse { counts })) 35}