mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Merge pull request #243 from meilisearch/all-updates-results
Introduce a function to get all updates results
This commit is contained in:
commit
32d2cc3aea
@ -40,7 +40,7 @@ struct IndexCommand {
|
|||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
struct SearchCommand {
|
struct SearchCommand {
|
||||||
/// The destination where the database must be created.
|
/// The path of the database to work with.
|
||||||
#[structopt(parse(from_os_str))]
|
#[structopt(parse(from_os_str))]
|
||||||
database_path: PathBuf,
|
database_path: PathBuf,
|
||||||
|
|
||||||
@ -65,10 +65,18 @@ struct SearchCommand {
|
|||||||
displayed_fields: Vec<String>,
|
displayed_fields: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, StructOpt)]
|
||||||
|
struct ShowUpdatesCommand {
|
||||||
|
/// The path of the database to work with.
|
||||||
|
#[structopt(parse(from_os_str))]
|
||||||
|
database_path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
enum Command {
|
enum Command {
|
||||||
Index(IndexCommand),
|
Index(IndexCommand),
|
||||||
Search(SearchCommand),
|
Search(SearchCommand),
|
||||||
|
ShowUpdates(ShowUpdatesCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
@ -76,6 +84,7 @@ impl Command {
|
|||||||
match self {
|
match self {
|
||||||
Command::Index(command) => &command.database_path,
|
Command::Index(command) => &command.database_path,
|
||||||
Command::Search(command) => &command.database_path,
|
Command::Search(command) => &command.database_path,
|
||||||
|
Command::ShowUpdates(command) => &command.database_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,6 +312,7 @@ fn search_command(command: SearchCommand, database: Database) -> Result<(), Box<
|
|||||||
let reader = env.read_txn().unwrap();
|
let reader = env.read_txn().unwrap();
|
||||||
let schema = index.main.schema(&reader)?;
|
let schema = index.main.schema(&reader)?;
|
||||||
reader.abort();
|
reader.abort();
|
||||||
|
|
||||||
let schema = schema.ok_or(meilidb_core::Error::SchemaMissing)?;
|
let schema = schema.ok_or(meilidb_core::Error::SchemaMissing)?;
|
||||||
|
|
||||||
let fields = command.displayed_fields.iter().map(String::as_str);
|
let fields = command.displayed_fields.iter().map(String::as_str);
|
||||||
@ -418,6 +428,23 @@ fn search_command(command: SearchCommand, database: Database) -> Result<(), Box<
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn show_updates_command(
|
||||||
|
_command: ShowUpdatesCommand,
|
||||||
|
database: Database,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
|
let env = &database.env;
|
||||||
|
let index = database
|
||||||
|
.open_index(INDEX_NAME)
|
||||||
|
.expect("Could not find index");
|
||||||
|
|
||||||
|
let reader = env.read_txn().unwrap();
|
||||||
|
let updates = index.all_updates_status(&reader)?;
|
||||||
|
println!("{:#?}", updates);
|
||||||
|
reader.abort();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
@ -427,5 +454,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
match opt {
|
match opt {
|
||||||
Command::Index(command) => index_command(command, database),
|
Command::Index(command) => index_command(command, database),
|
||||||
Command::Search(command) => search_command(command, database),
|
Command::Search(command) => search_command(command, database),
|
||||||
|
Command::ShowUpdates(command) => show_updates_command(command, database),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,6 +202,20 @@ impl Index {
|
|||||||
update::update_status(reader, self.updates, self.updates_results, update_id)
|
update::update_status(reader, self.updates, self.updates_results, update_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn all_updates_status(&self, reader: &heed::RoTxn) -> MResult<Vec<update::UpdateStatus>> {
|
||||||
|
match self.updates_results.last_update_id(reader)? {
|
||||||
|
Some((last_id, _)) => {
|
||||||
|
let mut updates = Vec::with_capacity(last_id as usize + 1);
|
||||||
|
for id in 0..=last_id {
|
||||||
|
let update = self.update_status(reader, id)?;
|
||||||
|
updates.push(update);
|
||||||
|
}
|
||||||
|
Ok(updates)
|
||||||
|
}
|
||||||
|
None => Ok(Vec::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn query_builder(&self) -> QueryBuilder {
|
pub fn query_builder(&self) -> QueryBuilder {
|
||||||
QueryBuilder::new(
|
QueryBuilder::new(
|
||||||
self.main,
|
self.main,
|
||||||
|
@ -47,12 +47,12 @@ pub enum UpdateType {
|
|||||||
SynonymsDeletion { number: usize },
|
SynonymsDeletion { number: usize },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct DetailedDuration {
|
pub struct DetailedDuration {
|
||||||
pub main: Duration,
|
pub main: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct UpdateResult {
|
pub struct UpdateResult {
|
||||||
pub update_id: u64,
|
pub update_id: u64,
|
||||||
pub update_type: UpdateType,
|
pub update_type: UpdateType,
|
||||||
@ -60,7 +60,7 @@ pub struct UpdateResult {
|
|||||||
pub detailed_duration: DetailedDuration,
|
pub detailed_duration: DetailedDuration,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum UpdateStatus {
|
pub enum UpdateStatus {
|
||||||
Enqueued,
|
Enqueued,
|
||||||
Processed(UpdateResult),
|
Processed(UpdateResult),
|
||||||
|
Loading…
Reference in New Issue
Block a user