fix the autobatched document deletion

This commit is contained in:
Irevoire 2022-10-22 15:59:30 +02:00 committed by Clément Renault
parent f6963f9662
commit c8ee453b6c
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 5 additions and 5 deletions

View File

@ -72,7 +72,8 @@ pub(crate) enum IndexOperation {
}, },
DocumentDeletion { DocumentDeletion {
index_uid: String, index_uid: String,
documents: Vec<String>, // The vec associated with each document deletion tasks.
documents: Vec<Vec<String>>,
tasks: Vec<Task>, tasks: Vec<Task>,
}, },
DocumentClear { DocumentClear {
@ -222,7 +223,7 @@ impl IndexScheduler {
for task in &tasks { for task in &tasks {
match task.kind { match task.kind {
KindWithContent::DocumentDeletion { ref documents_ids, .. } => { KindWithContent::DocumentDeletion { ref documents_ids, .. } => {
documents.extend_from_slice(documents_ids) documents.push(documents_ids.clone())
} }
_ => unreachable!(), _ => unreachable!(),
} }
@ -912,7 +913,7 @@ impl IndexScheduler {
} }
IndexOperation::DocumentDeletion { index_uid: _, documents, mut tasks } => { IndexOperation::DocumentDeletion { index_uid: _, documents, mut tasks } => {
let mut builder = milli::update::DeleteDocuments::new(index_wtxn, index)?; let mut builder = milli::update::DeleteDocuments::new(index_wtxn, index)?;
documents.iter().for_each(|id| { documents.iter().flatten().for_each(|id| {
builder.delete_external_id(id); builder.delete_external_id(id);
}); });
@ -922,7 +923,7 @@ impl IndexScheduler {
task.status = Status::Succeeded; task.status = Status::Succeeded;
task.details = Some(Details::DocumentDeletion { task.details = Some(Details::DocumentDeletion {
received_document_ids: documents.len(), received_document_ids: documents.len(),
deleted_documents: Some(deleted_documents), deleted_documents: Some(deleted_documents.min(documents.len() as u64)),
}); });
} }

View File

@ -560,7 +560,6 @@ async fn error_add_missing_payload_ndjson_documents() {
let status_code = res.status(); let status_code = res.status();
let body = test::read_body(res).await; let body = test::read_body(res).await;
let response: Value = serde_json::from_slice(&body).unwrap_or_default(); let response: Value = serde_json::from_slice(&body).unwrap_or_default();
dbg!(&response);
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["message"], json!(r#"A ndjson payload is missing."#)); assert_eq!(response["message"], json!(r#"A ndjson payload is missing."#));
assert_eq!(response["code"], json!("missing_payload")); assert_eq!(response["code"], json!("missing_payload"));