From 12b80e08be73702a03451b619033957e3b68debb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 11 Oct 2019 11:29:47 +0200 Subject: [PATCH] Do not commit updates, let the user do --- meilidb-core/examples/from_file.rs | 12 ++++++++---- meilidb-core/src/store/mod.rs | 5 ++--- meilidb-core/src/update/documents_addition.rs | 8 +++----- meilidb-core/src/update/documents_deletion.rs | 8 +++----- meilidb-core/src/update/synonyms_addition.rs | 8 +++----- meilidb-core/src/update/synonyms_deletion.rs | 8 +++----- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/meilidb-core/examples/from_file.rs b/meilidb-core/examples/from_file.rs index 5162911b7..42113e32b 100644 --- a/meilidb-core/examples/from_file.rs +++ b/meilidb-core/examples/from_file.rs @@ -101,7 +101,7 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box { if current_schema != schema { @@ -109,7 +109,10 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box index.schema_update(writer, schema)?, + None => { + index.schema_update(&mut writer, schema)?; + writer.commit().unwrap(); + }, } let mut rdr = csv::Reader::from_path(command.csv_data_path)?; @@ -147,9 +150,10 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box MResult<()> { - update::push_schema_update(&mut writer, self.updates, self.updates_results, schema)?; - writer.commit()?; + pub fn schema_update(&self, writer: &mut rkv::Writer, schema: Schema) -> MResult<()> { let _ = self.updates_notifier.send(()); + update::push_schema_update(writer, self.updates, self.updates_results, schema)?; Ok(()) } diff --git a/meilidb-core/src/update/documents_addition.rs b/meilidb-core/src/update/documents_addition.rs index d0eb6a8b5..31107665c 100644 --- a/meilidb-core/src/update/documents_addition.rs +++ b/meilidb-core/src/update/documents_addition.rs @@ -36,18 +36,16 @@ impl DocumentsAddition { self.documents.push(document); } - pub fn finalize(self, mut writer: rkv::Writer) -> MResult + pub fn finalize(self, writer: &mut rkv::Writer) -> MResult where D: serde::Serialize { + let _ = self.updates_notifier.send(()); let update_id = push_documents_addition( - &mut writer, + writer, self.updates_store, self.updates_results_store, self.documents, )?; - writer.commit()?; - let _ = self.updates_notifier.send(()); - Ok(update_id) } } diff --git a/meilidb-core/src/update/documents_deletion.rs b/meilidb-core/src/update/documents_deletion.rs index c17452ea9..765eb52f2 100644 --- a/meilidb-core/src/update/documents_deletion.rs +++ b/meilidb-core/src/update/documents_deletion.rs @@ -49,16 +49,14 @@ impl DocumentsDeletion { Ok(()) } - pub fn finalize(self, mut writer: rkv::Writer) -> MResult { + pub fn finalize(self, writer: &mut rkv::Writer) -> MResult { + let _ = self.updates_notifier.send(()); let update_id = push_documents_deletion( - &mut writer, + writer, self.updates_store, self.updates_results_store, self.documents, )?; - writer.commit()?; - let _ = self.updates_notifier.send(()); - Ok(update_id) } } diff --git a/meilidb-core/src/update/synonyms_addition.rs b/meilidb-core/src/update/synonyms_addition.rs index 7ed24a3d7..ad2f03f23 100644 --- a/meilidb-core/src/update/synonyms_addition.rs +++ b/meilidb-core/src/update/synonyms_addition.rs @@ -39,16 +39,14 @@ impl SynonymsAddition { self.synonyms.entry(synonym).or_insert_with(Vec::new).extend(alternatives); } - pub fn finalize(self, mut writer: rkv::Writer) -> MResult { + pub fn finalize(self, writer: &mut rkv::Writer) -> MResult { + let _ = self.updates_notifier.send(()); let update_id = push_synonyms_addition( - &mut writer, + writer, self.updates_store, self.updates_results_store, self.synonyms, )?; - writer.commit()?; - let _ = self.updates_notifier.send(()); - Ok(update_id) } } diff --git a/meilidb-core/src/update/synonyms_deletion.rs b/meilidb-core/src/update/synonyms_deletion.rs index 1acb553e1..fe8baefc6 100644 --- a/meilidb-core/src/update/synonyms_deletion.rs +++ b/meilidb-core/src/update/synonyms_deletion.rs @@ -49,16 +49,14 @@ impl SynonymsDeletion { } } - pub fn finalize(self, mut writer: rkv::Writer) -> MResult { + pub fn finalize(self, writer: &mut rkv::Writer) -> MResult { + let _ = self.updates_notifier.send(()); let update_id = push_synonyms_deletion( - &mut writer, + writer, self.updates_store, self.updates_results_store, self.synonyms, )?; - writer.commit()?; - let _ = self.updates_notifier.send(()); - Ok(update_id) } }