Fix the prefix deletion

This commit is contained in:
Clément Renault 2024-10-15 11:20:09 +02:00
parent 1e81d72b5f
commit 9a0e1dc375
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
2 changed files with 4 additions and 32 deletions

View File

@ -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<u8>,
) -> Result<Box<KvReaderFieldId>> {
let result: Result<BTreeMap<_, _>> = 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())
}

View File

@ -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()? };
}
}