2021-09-21 19:23:22 +08:00
|
|
|
#[macro_use]
|
|
|
|
pub mod error;
|
|
|
|
pub mod options;
|
|
|
|
|
2021-12-02 23:03:26 +08:00
|
|
|
mod analytics;
|
2021-09-21 19:23:22 +08:00
|
|
|
pub mod index;
|
|
|
|
pub mod index_controller;
|
2021-12-02 23:03:26 +08:00
|
|
|
mod index_resolver;
|
|
|
|
mod snapshot;
|
|
|
|
pub mod tasks;
|
|
|
|
mod update_file_store;
|
2021-09-21 19:23:22 +08:00
|
|
|
|
2022-01-20 23:00:14 +08:00
|
|
|
use std::path::Path;
|
|
|
|
|
2021-10-06 19:01:02 +08:00
|
|
|
pub use index_controller::MeiliSearch;
|
2021-09-29 04:08:03 +08:00
|
|
|
pub use milli;
|
2022-03-24 22:30:10 +08:00
|
|
|
pub use milli::heed;
|
2021-09-29 04:08:03 +08:00
|
|
|
|
2021-09-27 22:48:03 +08:00
|
|
|
mod compression;
|
2021-10-21 03:20:28 +08:00
|
|
|
pub mod document_formats;
|
2021-09-27 22:48:03 +08:00
|
|
|
|
2021-09-21 19:23:22 +08:00
|
|
|
use walkdir::WalkDir;
|
|
|
|
|
|
|
|
pub trait EnvSizer {
|
|
|
|
fn size(&self) -> u64;
|
|
|
|
}
|
|
|
|
|
2022-03-16 20:45:58 +08:00
|
|
|
impl EnvSizer for milli::heed::Env {
|
2021-09-21 19:23:22 +08:00
|
|
|
fn size(&self) -> u64 {
|
|
|
|
WalkDir::new(self.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())
|
|
|
|
}
|
|
|
|
}
|
2022-01-20 23:00:14 +08:00
|
|
|
|
|
|
|
/// Check if a db is empty. It does not provide any information on the
|
|
|
|
/// validity of the data in it.
|
|
|
|
/// We consider a database as non empty when it's a non empty directory.
|
|
|
|
pub fn is_empty_db(db_path: impl AsRef<Path>) -> bool {
|
|
|
|
let db_path = db_path.as_ref();
|
|
|
|
|
|
|
|
if !db_path.exists() {
|
|
|
|
true
|
|
|
|
// if we encounter an error or if the db is a file we consider the db non empty
|
|
|
|
} else if let Ok(dir) = db_path.read_dir() {
|
|
|
|
dir.count() == 0
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|