Implement the DocumentDeletion batch operation

This commit is contained in:
Kerollmops 2022-09-29 11:49:47 +02:00 committed by Clément Renault
parent 7a0f17c912
commit a6a1043abb
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 28 additions and 2 deletions

View File

@ -5,7 +5,7 @@ use crate::{
}; };
use index::{Settings, Unchecked}; use index::{Settings, Unchecked};
use milli::heed::RoTxn; use milli::heed::RoTxn;
use milli::update::{DocumentAdditionResult, IndexDocumentsMethod}; use milli::update::{DocumentAdditionResult, DocumentDeletionResult, IndexDocumentsMethod};
use uuid::Uuid; use uuid::Uuid;
pub(crate) enum Batch { pub(crate) enum Batch {
@ -487,7 +487,32 @@ impl IndexScheduler {
index_uid, index_uid,
documents, documents,
tasks, tasks,
} => todo!(), } => {
let rtxn = self.env.read_txn()?;
let index = self.index_mapper.index(&rtxn, &index_uid)?;
let ret = index.delete_documents(&documents);
for task in tasks {
match ret {
Ok(DocumentDeletionResult {
deleted_documents,
remaining_documents: _,
}) => {
// TODO we are assigning the same amount of documents to
// all the tasks that are in the same batch. That's wrong!
task.details = Some(Details::DocumentDeletion {
received_document_ids: documents.len(),
deleted_documents: Some(deleted_documents),
});
}
Err(error) => {
task.error = Some(error.into());
}
}
}
Ok(tasks)
}
Batch::Settings { Batch::Settings {
index_uid, index_uid,
settings, settings,

View File

@ -327,6 +327,7 @@ pub enum Details {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
DocumentDeletion { DocumentDeletion {
received_document_ids: usize, received_document_ids: usize,
// TODO why is this optional?
deleted_documents: Option<u64>, deleted_documents: Option<u64>,
}, },
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]