use {
crate::{
Partitions,
protocol::{
jsonrpc,
lsp::LanguageServer,
},
scheduler::task::TaskContext,
},
otel::{
event,
exception,
},
serde_json::Value,
};
pub async fn handle_db_stats<P: Partitions, T: LanguageServer<P>>(
_arguments: &[Value],
ctx: &mut TaskContext<P, T>,
) -> jsonrpc::Result<Option<Value>> {
let query_client = ctx.query_client();
let db = &query_client.db;
let stats = crate::database::stats::collect_stats(db);
event!(
"db_stats.collected",
"total_index_entries" = stats.total_index_entries as i64,
"current_epoch" = stats.current_epoch.get() as i64
);
let json = serde_json::to_value(stats).map_err(|e| {
exception!(
"serialization_failed",
jsonrpc::Error::invalid_params(format!(
"Failed to serialize stats: {}",
e
))
)
})?;
Ok(Some(json))
}