From 9a0e1dc37501f927aacb1337da33a0ec01659d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 15 Oct 2024 11:20:09 +0200 Subject: [PATCH] Fix the prefix deletion --- .../update/new/indexer/update_by_function.rs | 29 ------------------- milli/src/update/new/words_prefix_docids.rs | 7 +++-- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/milli/src/update/new/indexer/update_by_function.rs b/milli/src/update/new/indexer/update_by_function.rs index 6bde29b45..6f2914577 100644 --- a/milli/src/update/new/indexer/update_by_function.rs +++ b/milli/src/update/new/indexer/update_by_function.rs @@ -204,32 +204,3 @@ fn rhaimap_to_object(map: rhai::Map) -> Object { } output } - -fn rhaimap_to_obkv( - map: rhai::Map, - global_fields_ids_map: &mut GlobalFieldsIdsMap, - buffer: &mut Vec, -) -> Result> { - let result: Result> = map - .keys() - .map(|key| { - global_fields_ids_map - .id_or_insert(key) - .ok_or(UserError::AttributeLimitReached) - .map_err(Error::from) - .map(|fid| (fid, key)) - }) - .collect(); - - let ordered_fields = result?; - let mut writer = KvWriterFieldId::memory(); - for (fid, key) in ordered_fields { - let value = map.get(key).unwrap(); - let value = serde_json::to_value(value).unwrap(); - buffer.clear(); - serde_json::to_writer(&mut *buffer, &value).unwrap(); - writer.insert(fid, &buffer)?; - } - - Ok(writer.into_boxed()) -} diff --git a/milli/src/update/new/words_prefix_docids.rs b/milli/src/update/new/words_prefix_docids.rs index d45f6397e..38c2b1744 100644 --- a/milli/src/update/new/words_prefix_docids.rs +++ b/milli/src/update/new/words_prefix_docids.rs @@ -128,9 +128,10 @@ fn delete_prefixes( ) -> Result<()> { // We remove all the entries that are no more required in this word prefix docids database. for prefix in prefixes { - let prefix = prefix.as_bytes(); - if !prefix_database.delete(wtxn, prefix)? { - unreachable!("We tried to delete an unknown key") + let mut iter = prefix_database.prefix_iter_mut(wtxn, prefix.as_bytes())?; + while iter.next().transpose()?.is_some() { + // safety: we do not keep a reference on database entries. + unsafe { iter.del_current()? }; } }