Remove infinite loop in import_vectors

This commit is contained in:
Louis Dureuil 2024-11-18 12:41:51 +01:00
parent e9d17136b2
commit e736a74729
No known key found for this signature in database

View File

@ -70,28 +70,30 @@ impl<'t, Mapper: FieldIdMapper> Document<'t> for DocumentFromDb<'t, Mapper> {
fn iter_top_level_fields(&self) -> impl Iterator<Item = Result<(&'t str, &'t RawValue)>> { fn iter_top_level_fields(&self) -> impl Iterator<Item = Result<(&'t str, &'t RawValue)>> {
let mut it = self.content.iter(); let mut it = self.content.iter();
std::iter::from_fn(move || { std::iter::from_fn(move || loop {
let (fid, value) = it.next()?; let (fid, value) = it.next()?;
let name = match self.fields_ids_map.name(fid).ok_or(
let res = (|| loop {
let name = self.fields_ids_map.name(fid).ok_or(
InternalError::FieldIdMapMissingEntry(crate::FieldIdMapMissingEntry::FieldId { InternalError::FieldIdMapMissingEntry(crate::FieldIdMapMissingEntry::FieldId {
field_id: fid, field_id: fid,
process: "getting current document", process: "getting current document",
}), }),
)?; ) {
Ok(name) => name,
Err(error) => return Some(Err(error.into())),
};
if name == RESERVED_VECTORS_FIELD_NAME || name == "_geo" { if name == RESERVED_VECTORS_FIELD_NAME || name == "_geo" {
continue; continue;
} }
let res = (|| {
let value = let value =
serde_json::from_slice(value).map_err(crate::InternalError::SerdeJson)?; serde_json::from_slice(value).map_err(crate::InternalError::SerdeJson)?;
return Ok((name, value)); Ok((name, value))
})(); })();
Some(res) return Some(res);
}) })
} }