mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-10 05:24:32 +01:00
Update after review
This commit is contained in:
parent
3648abbfd5
commit
8ee3793259
@ -66,7 +66,7 @@ impl FacetsUpdateIncremental {
|
|||||||
FacetFieldIdChange { facet_value: right, .. }| left.cmp(right),
|
FacetFieldIdChange { facet_value: right, .. }| left.cmp(right),
|
||||||
);
|
);
|
||||||
|
|
||||||
self.inner.find_touched_parents(
|
self.inner.find_changed_parents(
|
||||||
wtxn,
|
wtxn,
|
||||||
0,
|
0,
|
||||||
self.delta_data
|
self.delta_data
|
||||||
@ -81,21 +81,21 @@ impl FacetsUpdateIncremental {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FacetsUpdateIncrementalInner {
|
impl FacetsUpdateIncrementalInner {
|
||||||
/// WARNING: `touched_children` must be sorted in **reverse** lexicographic order.
|
/// WARNING: `changed_children` must be sorted in **reverse** lexicographic order.
|
||||||
fn find_touched_parents(
|
fn find_changed_parents(
|
||||||
&self,
|
&self,
|
||||||
wtxn: &mut RwTxn,
|
wtxn: &mut RwTxn,
|
||||||
child_level: u8,
|
child_level: u8,
|
||||||
mut touched_children: impl Iterator<Item = Vec<u8>>,
|
mut changed_children: impl Iterator<Item = Vec<u8>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut touched_parents = vec![];
|
let mut changed_parents = vec![];
|
||||||
let Some(parent_level) = child_level.checked_add(1) else { return Ok(()) };
|
let Some(parent_level) = child_level.checked_add(1) else { return Ok(()) };
|
||||||
let parent_level_left_bound: FacetGroupKey<&[u8]> =
|
let parent_level_left_bound: FacetGroupKey<&[u8]> =
|
||||||
FacetGroupKey { field_id: self.field_id, level: parent_level, left_bound: &[] };
|
FacetGroupKey { field_id: self.field_id, level: parent_level, left_bound: &[] };
|
||||||
|
|
||||||
let mut last_parent: Option<Vec<u8>> = None;
|
let mut last_parent: Option<Vec<u8>> = None;
|
||||||
|
|
||||||
for child in &mut touched_children {
|
for child in &mut changed_children {
|
||||||
if !valid_facet_value(&child) {
|
if !valid_facet_value(&child) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ impl FacetsUpdateIncrementalInner {
|
|||||||
last_parent = Some(parent_key.left_bound.to_owned());
|
last_parent = Some(parent_key.left_bound.to_owned());
|
||||||
|
|
||||||
// add to modified list for parent level
|
// add to modified list for parent level
|
||||||
touched_parents.push(parent_key.left_bound.to_owned());
|
changed_parents.push(parent_key.left_bound.to_owned());
|
||||||
self.compute_parent_group(wtxn, child_level, child)?;
|
self.compute_parent_group(wtxn, child_level, child)?;
|
||||||
}
|
}
|
||||||
Some(Err(err)) => return Err(err.into()),
|
Some(Err(err)) => return Err(err.into()),
|
||||||
@ -143,7 +143,7 @@ impl FacetsUpdateIncrementalInner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do we have children without parents?
|
// do we have children without parents?
|
||||||
if let Some(child) = touched_children.next() {
|
if let Some(child) = changed_children.next() {
|
||||||
// no parent for that key
|
// no parent for that key
|
||||||
let mut it = self
|
let mut it = self
|
||||||
.db
|
.db
|
||||||
@ -160,10 +160,10 @@ impl FacetsUpdateIncrementalInner {
|
|||||||
unsafe { it.del_current()? };
|
unsafe { it.del_current()? };
|
||||||
drop(it);
|
drop(it);
|
||||||
// pop all elements and order to visit the new left bound
|
// pop all elements and order to visit the new left bound
|
||||||
touched_parents.push(child.clone());
|
changed_parents.push(child.clone());
|
||||||
self.compute_parent_group(wtxn, child_level, child)?;
|
self.compute_parent_group(wtxn, child_level, child)?;
|
||||||
for child in touched_children {
|
for child in changed_children {
|
||||||
let new_left_bound = touched_parents.last_mut().unwrap();
|
let new_left_bound = changed_parents.last_mut().unwrap();
|
||||||
new_left_bound.clear();
|
new_left_bound.clear();
|
||||||
new_left_bound.extend_from_slice(&child);
|
new_left_bound.extend_from_slice(&child);
|
||||||
self.compute_parent_group(wtxn, child_level, child)?;
|
self.compute_parent_group(wtxn, child_level, child)?;
|
||||||
@ -174,17 +174,17 @@ impl FacetsUpdateIncrementalInner {
|
|||||||
None => {
|
None => {
|
||||||
drop(it);
|
drop(it);
|
||||||
self.compute_parent_group(wtxn, child_level, child)?;
|
self.compute_parent_group(wtxn, child_level, child)?;
|
||||||
for child in touched_children {
|
for child in changed_children {
|
||||||
self.compute_parent_group(wtxn, child_level, child)?;
|
self.compute_parent_group(wtxn, child_level, child)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !touched_parents.is_empty() {
|
if !changed_parents.is_empty() {
|
||||||
self.find_touched_parents(
|
self.find_changed_parents(
|
||||||
wtxn,
|
wtxn,
|
||||||
parent_level,
|
parent_level,
|
||||||
touched_parents
|
changed_parents
|
||||||
// no need to `rev` here because the parents were already visited in reverse order
|
// no need to `rev` here because the parents were already visited in reverse order
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
)?;
|
)?;
|
||||||
|
@ -10,14 +10,14 @@ use fst::{IntoStreamer, Streamer};
|
|||||||
pub use grenad_helpers::*;
|
pub use grenad_helpers::*;
|
||||||
pub use merge_functions::*;
|
pub use merge_functions::*;
|
||||||
|
|
||||||
use crate::MAX_WORD_LENGTH;
|
use crate::{MAX_LMDB_KEY_LENGTH, MAX_WORD_LENGTH};
|
||||||
|
|
||||||
pub fn valid_lmdb_key(key: impl AsRef<[u8]>) -> bool {
|
pub fn valid_lmdb_key(key: impl AsRef<[u8]>) -> bool {
|
||||||
key.as_ref().len() <= MAX_WORD_LENGTH * 2 && !key.as_ref().is_empty()
|
key.as_ref().len() <= MAX_WORD_LENGTH * 2 && !key.as_ref().is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn valid_facet_value(facet_value: impl AsRef<[u8]>) -> bool {
|
pub fn valid_facet_value(facet_value: impl AsRef<[u8]>) -> bool {
|
||||||
facet_value.as_ref().len() <= (MAX_WORD_LENGTH * 2) - 3 && !facet_value.as_ref().is_empty()
|
facet_value.as_ref().len() <= MAX_LMDB_KEY_LENGTH - 3 && !facet_value.as_ref().is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Divides one slice into two at an index, returns `None` if mid is out of bounds.
|
/// Divides one slice into two at an index, returns `None` if mid is out of bounds.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user