From 2a9184966076e7b9c16e185273f41c7b18a088b2 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Mon, 28 Oct 2024 14:21:50 +0100 Subject: [PATCH] Remove primary key from top id map --- milli/src/documents/primary_key.rs | 44 ++---------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/milli/src/documents/primary_key.rs b/milli/src/documents/primary_key.rs index 79fd07048..1831a2dbc 100644 --- a/milli/src/documents/primary_key.rs +++ b/milli/src/documents/primary_key.rs @@ -1,15 +1,14 @@ -use std::borrow::Cow; use std::iter; use std::ops::ControlFlow; use std::result::Result as StdResult; use bumpalo::Bump; use serde_json::value::RawValue; -use serde_json::{from_str, Value}; +use serde_json::Value; use crate::fields_ids_map::MutFieldIdMapper; use crate::update::new::indexer::de::{match_component, DeOrBumpStr}; -use crate::update::new::{CowStr, KvReaderFieldId, TopLevelMap}; +use crate::update::new::KvReaderFieldId; use crate::{FieldId, InternalError, Object, Result, UserError}; /// The symbol used to define levels in a nested primary key. @@ -230,45 +229,6 @@ impl<'a> PrimaryKey<'a> { Ok(external_document_id) } - /// Returns the document ID based on the primary and - /// search for it recursively in zero-copy-deserialized documents. - pub fn document_id_from_top_level_map<'p>( - &self, - document: &TopLevelMap<'p>, - ) -> Result, DocumentIdExtractionError>> { - fn get_docid<'p>( - document: &TopLevelMap<'p>, - primary_key: &[&str], - ) -> Result, DocumentIdExtractionError>> { - match primary_key { - [] => unreachable!("arrrgh"), // would None be ok? - [primary_key] => match document.0.get(*primary_key) { - Some(value) => match from_str::(value.get()) { - Ok(value) => Ok(Ok(CowStr(Cow::Owned(value.to_string())))), - Err(_) => match from_str(value.get()) { - Ok(document_id) => Ok(Ok(document_id)), - Err(e) => Ok(Err(DocumentIdExtractionError::InvalidDocumentId( - UserError::SerdeJson(e), - ))), - }, - }, - None => Ok(Err(DocumentIdExtractionError::MissingDocumentId)), - }, - [head, tail @ ..] => match document.0.get(*head) { - Some(value) => { - let document = from_str(value.get()).map_err(InternalError::SerdeJson)?; - get_docid(&document, tail) - } - None => Ok(Err(DocumentIdExtractionError::MissingDocumentId)), - }, - } - } - - /// TODO do not allocate a vec everytime here - let primary_key: Vec<_> = self.name().split(PRIMARY_KEY_SPLIT_SYMBOL).collect(); - get_docid(document, &primary_key) - } - /// Returns an `Iterator` that gives all the possible fields names the primary key /// can have depending of the first level name and depth of the objects. pub fn possible_level_names(&self) -> impl Iterator + '_ {