at protocol indexer with flexible filtering, xrpc queries, and a cursor-backed event stream, built on fjall
at-protocol atproto indexer rust fjall
at 6ad49bbce1f59c8a3d3f76d025d87b428e5057be 26 lines 808 B view raw
1use crate::api::AppState; 2use axum::{Json, extract::State, response::Result}; 3use serde::Serialize; 4use std::{collections::HashMap, sync::Arc}; 5 6#[derive(Serialize)] 7pub struct StatsResponse { 8 pub counts: HashMap<&'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: HashMap<&'static str, u64> = futures::future::join_all( 15 ["repos", "records", "blocks", "pending", "resync"] 16 .into_iter() 17 .map(|name| async move { (name, db.get_count(name).await) }), 18 ) 19 .await 20 .into_iter() 21 .collect(); 22 // this should be accurate since we dont remove events 23 counts.insert("events", db.events.approximate_len() as u64); 24 25 Ok(Json(StatsResponse { counts })) 26}