feat(http): stats route

This commit is contained in:
Alexey Shekhirin 2021-04-01 17:44:42 +03:00
parent a1d04fbff5
commit dd9eae8c26
No known key found for this signature in database
GPG key ID: AF9A26AA133B5B98
10 changed files with 199 additions and 60 deletions

View file

@ -1,6 +1,3 @@
mod search;
mod updates;
use std::collections::{BTreeSet, HashSet};
use std::ops::Deref;
use std::sync::Arc;
@ -8,10 +5,14 @@ use std::sync::Arc;
use anyhow::{bail, Context};
use milli::obkv_to_json;
use serde_json::{Map, Value};
use walkdir::WalkDir;
pub use search::{SearchQuery, SearchResult, DEFAULT_SEARCH_LIMIT};
pub use updates::{Facets, Settings, UpdateResult};
mod search;
mod updates;
pub type Document = Map<String, Value>;
#[derive(Clone)]
@ -126,6 +127,15 @@ impl Index {
}
}
pub fn size(&self) -> anyhow::Result<u64> {
Ok(WalkDir::new(self.env.path())
.into_iter()
.filter_map(|entry| entry.ok())
.filter_map(|entry| entry.metadata().ok())
.filter(|metadata| metadata.is_file())
.fold(0, |acc, m| acc + m.len()))
}
fn fields_to_display<S: AsRef<str>>(
&self,
txn: &heed::RoTxn,