mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
Simplify the document fields counts deletion
This commit is contained in:
parent
9ff92c5d15
commit
0de37819b4
@ -702,7 +702,7 @@ mod tests {
|
||||
|
||||
for ((docid, attr, _), count) in fields_counts {
|
||||
let prev = index.documents_fields_counts
|
||||
.document_attribute_count(
|
||||
.document_field_count(
|
||||
&mut writer,
|
||||
docid,
|
||||
SchemaAttr(attr),
|
||||
|
@ -27,19 +27,14 @@ impl DocumentsFieldsCounts {
|
||||
document_id: DocumentId,
|
||||
) -> Result<usize, rkv::StoreError>
|
||||
{
|
||||
let document_id_bytes = document_id.0.to_be_bytes();
|
||||
let mut keys_to_delete = Vec::new();
|
||||
|
||||
// WARN we can not delete the keys using the iterator
|
||||
// so we store them and delete them just after
|
||||
let iter = self.documents_fields_counts.iter_from(writer, document_id_bytes)?;
|
||||
for result in iter {
|
||||
let (key, _) = result?;
|
||||
let array = TryFrom::try_from(key).unwrap();
|
||||
let (current_document_id, _) = document_attribute_from_key(array);
|
||||
if current_document_id != document_id { break }
|
||||
|
||||
keys_to_delete.push(key.to_owned());
|
||||
for result in self.document_fields_counts(writer, document_id)? {
|
||||
let (attribute, _) = result?;
|
||||
let key = document_attribute_into_key(document_id, attribute);
|
||||
keys_to_delete.push(key);
|
||||
}
|
||||
|
||||
let count = keys_to_delete.len();
|
||||
@ -50,9 +45,9 @@ impl DocumentsFieldsCounts {
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
pub fn document_attribute_count<'a>(
|
||||
pub fn document_field_count(
|
||||
&self,
|
||||
reader: &'a impl rkv::Readable,
|
||||
reader: &impl rkv::Readable,
|
||||
document_id: DocumentId,
|
||||
attribute: SchemaAttr,
|
||||
) -> Result<Option<u64>, rkv::StoreError>
|
||||
@ -92,7 +87,7 @@ pub struct DocumentFieldsCountsIter<'r> {
|
||||
iter: rkv::store::single::Iter<'r>,
|
||||
}
|
||||
|
||||
impl<'r> Iterator for DocumentFieldsCountsIter<'r> {
|
||||
impl Iterator for DocumentFieldsCountsIter<'_> {
|
||||
type Item = Result<(SchemaAttr, u64), rkv::StoreError>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
@ -116,7 +111,7 @@ pub struct DocumentsIdsIter<'r> {
|
||||
iter: rkv::store::single::Iter<'r>,
|
||||
}
|
||||
|
||||
impl<'r> Iterator for DocumentsIdsIter<'r> {
|
||||
impl Iterator for DocumentsIdsIter<'_> {
|
||||
type Item = Result<DocumentId, rkv::StoreError>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{store, error::UnsupportedOperation, MResult};
|
||||
use crate::update::{Update, next_update_id};
|
||||
use crate::{store, MResult};
|
||||
|
||||
pub fn apply_customs_update(
|
||||
writer: &mut rkv::Writer,
|
||||
|
Loading…
Reference in New Issue
Block a user