From 290e773d23a4c0108b9c9330ed2a5ca76028e973 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 25 Oct 2023 14:49:25 +0200 Subject: [PATCH] remove more warnings and fix some tests --- milli/src/index.rs | 10 +++----- milli/src/snapshot_tests.rs | 3 +-- milli/src/update/facet/mod.rs | 2 +- milli/src/update/index_documents/mod.rs | 25 ++++++-------------- milli/src/update/prefix_word_pairs/mod.rs | 28 ++++------------------- milli/src/update/settings.rs | 10 +++----- 6 files changed, 19 insertions(+), 59 deletions(-) diff --git a/milli/src/index.rs b/milli/src/index.rs index 64aff636b..a280a1a48 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -1861,8 +1861,7 @@ pub(crate) mod tests { use big_s::S; use maplit::hashset; - let mut index = TempIndex::new(); - let index = index; + let index = TempIndex::new(); index .update_settings(|settings| { @@ -1973,7 +1972,7 @@ pub(crate) mod tests { use big_s::S; use maplit::hashset; - let mut index = TempIndex::new(); + let index = TempIndex::new(); index .update_settings(|settings| { @@ -2561,10 +2560,7 @@ pub(crate) mod tests { 4 2 "###); - let mut wtxn = index.write_txn().unwrap(); - let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - delete.execute().unwrap(); - wtxn.commit().unwrap(); + index.delete_documents(Default::default()); db_snap!(index, documents_ids, @"[0, 2, 3, ]"); db_snap!(index, external_documents_ids, @r###" diff --git a/milli/src/snapshot_tests.rs b/milli/src/snapshot_tests.rs index c22038f81..1d8d63277 100644 --- a/milli/src/snapshot_tests.rs +++ b/milli/src/snapshot_tests.rs @@ -4,9 +4,8 @@ use std::path::Path; use roaring::RoaringBitmap; -use crate::facet::FacetType; use crate::heed_codec::facet::{FacetGroupKey, FacetGroupValue}; -use crate::{make_db_snap_from_iter, obkv_to_json, ExternalDocumentsIds, Index}; +use crate::{make_db_snap_from_iter, obkv_to_json, Index}; #[track_caller] pub fn default_db_snapshot_settings_for_test(name: Option<&str>) -> (insta::Settings, String) { diff --git a/milli/src/update/facet/mod.rs b/milli/src/update/facet/mod.rs index 70a5e24c8..05e6a93d8 100644 --- a/milli/src/update/facet/mod.rs +++ b/milli/src/update/facet/mod.rs @@ -566,7 +566,7 @@ mod tests { #[test] fn replace_all_identical_soft_deletion_then_hard_deletion() { - let mut index = TempIndex::new_with_map_size(4096 * 1000 * 100); + let index = TempIndex::new_with_map_size(4096 * 1000 * 100); index .update_settings(|settings| { diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 864e13d04..c1e40373f 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -696,7 +696,6 @@ mod tests { use crate::documents::documents_batch_reader_from_objects; use crate::index::tests::TempIndex; use crate::search::TermsMatchingStrategy; - use crate::update::DeleteDocuments; use crate::{db_snap, BEU16}; #[test] @@ -1101,17 +1100,15 @@ mod tests { { "objectId": 30, "title": "Hamlet", "_geo": { "lat": 12, "lng": 89 } } ])) .unwrap(); - let mut wtxn = index.write_txn().unwrap(); - assert_eq!(index.primary_key(&wtxn).unwrap(), Some("objectId")); // Delete not all of the documents but some of them. - let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - builder.delete_external_id("30"); - builder.execute().unwrap(); + index.delete_document("30"); - let external_documents_ids = index.external_documents_ids(&wtxn).unwrap(); + let txn = index.read_txn().unwrap(); + assert_eq!(index.primary_key(&txn).unwrap(), Some("objectId")); + + let external_documents_ids = index.external_documents_ids(&txn).unwrap(); assert!(external_documents_ids.get("30").is_none()); - wtxn.commit().unwrap(); index .add_documents(documents!([ @@ -2493,16 +2490,8 @@ mod tests { db_snap!(index, word_fid_docids, 2, @"a48d3f88db33f94bc23110a673ea49e4"); db_snap!(index, word_position_docids, 2, @"3c9e66c6768ae2cf42b46b2c46e46a83"); - let mut wtxn = index.write_txn().unwrap(); - // Delete not all of the documents but some of them. - let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - builder.delete_external_id("0"); - builder.delete_external_id("3"); - let result = builder.execute().unwrap(); - println!("{result:?}"); - - wtxn.commit().unwrap(); + index.delete_documents(vec!["0".into(), "3".into()]); db_snap!(index, word_fid_docids, 3, @"4c2e2a1832e5802796edc1638136d933"); db_snap!(index, word_position_docids, 3, @"74f556b91d161d997a89468b4da1cb8f"); @@ -2557,7 +2546,7 @@ mod tests { ), ] */ - let mut index = TempIndex::new(); + let index = TempIndex::new(); // START OF BATCH diff --git a/milli/src/update/prefix_word_pairs/mod.rs b/milli/src/update/prefix_word_pairs/mod.rs index d6aa8e5a3..1ec57e080 100644 --- a/milli/src/update/prefix_word_pairs/mod.rs +++ b/milli/src/update/prefix_word_pairs/mod.rs @@ -142,9 +142,6 @@ pub fn write_into_lmdb_database_without_merging( #[cfg(test)] mod tests { use std::io::Cursor; - use std::iter::FromIterator; - - use roaring::RoaringBitmap; use crate::db_snap; use crate::documents::{DocumentsBatchBuilder, DocumentsBatchReader}; @@ -335,22 +332,14 @@ mod tests { db_snap!(index, word_prefix_pair_proximity_docids, "initial"); db_snap!(index, prefix_word_pair_proximity_docids, "initial"); - let mut wtxn = index.write_txn().unwrap(); - let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - delete.delete_documents(&RoaringBitmap::from_iter([50])); - delete.execute().unwrap(); - wtxn.commit().unwrap(); + index.delete_document("9000"); db_snap!(index, documents_ids, "first_delete"); db_snap!(index, word_docids, "first_delete"); db_snap!(index, word_prefix_pair_proximity_docids, "first_delete"); db_snap!(index, prefix_word_pair_proximity_docids, "first_delete"); - let mut wtxn = index.write_txn().unwrap(); - let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - delete.delete_documents(&RoaringBitmap::from_iter(0..50)); - delete.execute().unwrap(); - wtxn.commit().unwrap(); + index.delete_documents((0..50).map(|id| id.to_string()).collect()); db_snap!(index, documents_ids, "second_delete"); db_snap!(index, word_docids, "second_delete"); @@ -417,23 +406,14 @@ mod tests { db_snap!(index, word_prefix_pair_proximity_docids, "initial"); db_snap!(index, prefix_word_pair_proximity_docids, "initial"); - let mut wtxn = index.write_txn().unwrap(); - let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - delete.delete_documents(&RoaringBitmap::from_iter([50])); - delete.execute().unwrap(); - wtxn.commit().unwrap(); + index.delete_document("9000"); db_snap!(index, documents_ids, "first_delete"); db_snap!(index, word_docids, "first_delete"); db_snap!(index, word_prefix_pair_proximity_docids, "first_delete"); db_snap!(index, prefix_word_pair_proximity_docids, "first_delete"); - let mut wtxn = index.write_txn().unwrap(); - let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - - delete.delete_documents(&RoaringBitmap::from_iter(0..50)); - delete.execute().unwrap(); - wtxn.commit().unwrap(); + index.delete_documents((0..50).map(|id| id.to_string()).collect()); db_snap!(index, documents_ids, "second_delete"); db_snap!(index, word_docids, "second_delete"); diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index c2c0e9084..fd7ffa760 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -923,7 +923,7 @@ mod tests { use super::*; use crate::error::Error; use crate::index::tests::TempIndex; - use crate::update::{ClearDocuments, DeleteDocuments}; + use crate::update::ClearDocuments; use crate::{Criterion, Filter, SearchResult}; #[test] @@ -1768,13 +1768,9 @@ mod tests { } index.add_documents(documents! { docs }).unwrap(); - let mut wtxn = index.write_txn().unwrap(); - let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap(); - (0..5).for_each(|id| { - builder.delete_external_id(&id.to_string()); - }); - builder.execute().unwrap(); + index.delete_documents((0..5).map(|id| id.to_string()).collect()); + let mut wtxn = index.write_txn().unwrap(); index .update_settings_using_wtxn(&mut wtxn, |settings| { settings.set_searchable_fields(vec!["id".to_string()]);