fixes after review

This commit is contained in:
Alexey Shekhirin
2021-04-08 16:35:28 +03:00
parent 698a1ea582
commit ae1655586c
9 changed files with 56 additions and 89 deletions

View File

@ -4,9 +4,11 @@ use std::sync::Arc;
use sha2::Digest;
use crate::index::Settings;
use crate::index_controller::IndexController;
use crate::index_controller::{IndexController, IndexStats};
use crate::index_controller::{IndexMetadata, IndexSettings};
use crate::option::Opt;
use std::collections::HashMap;
use chrono::{DateTime, Utc};
pub mod search;
mod updates;
@ -37,6 +39,13 @@ pub struct ApiKeys {
pub master: Option<String>,
}
#[derive(Default)]
pub struct Stats {
pub database_size: u64,
pub last_update: Option<DateTime<Utc>>,
pub indexes: HashMap<String, IndexStats>,
}
impl ApiKeys {
pub fn generate_missing_api_keys(&mut self) {
if let Some(master_key) = &self.master {
@ -104,6 +113,27 @@ impl Data {
Ok(meta)
}
pub async fn get_index_stats(&self, uid: String) -> anyhow::Result<IndexStats> {
Ok(self.index_controller.get_stats(uid).await?)
}
pub async fn get_stats(&self) -> anyhow::Result<Stats> {
let mut stats = Stats::default();
for index in self.index_controller.list_indexes().await? {
let index_stats = self.index_controller.get_stats(index.uid.clone()).await?;
stats.database_size += index_stats.size;
stats.last_update = Some(match stats.last_update {
Some(last_update) => last_update.max(index.meta.updated_at),
None => index.meta.updated_at,
});
stats.indexes.insert(index.uid, index_stats);
}
Ok(stats)
}
#[inline]
pub fn http_payload_size_limit(&self) -> usize {
self.options.http_payload_size_limit.get_bytes() as usize