From 8fc3b7d3b0d76e31d768ad74c8a3836cb621d4d8 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Thu, 2 Jun 2022 15:11:50 +0200 Subject: [PATCH] refactor process_document_addition_batch --- meilisearch-lib/src/index_resolver/mod.rs | 11 +++++------ .../src/tasks/handlers/index_resolver_handler.rs | 6 ++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/meilisearch-lib/src/index_resolver/mod.rs b/meilisearch-lib/src/index_resolver/mod.rs index 97265e509..316528647 100644 --- a/meilisearch-lib/src/index_resolver/mod.rs +++ b/meilisearch-lib/src/index_resolver/mod.rs @@ -170,7 +170,7 @@ mod real { } } - pub async fn process_document_addition_batch(&self, mut tasks: Vec) -> Vec { + pub async fn process_document_addition_batch(&self, tasks: &mut [Task]) { fn get_content_uuid(task: &Task) -> Uuid { match task { Task { @@ -218,7 +218,8 @@ mod real { timestamp: now, }); } - return tasks; + + return; } }; @@ -253,8 +254,6 @@ mod real { for task in tasks.iter_mut() { task.events.push(event.clone()); } - - tasks } _ => panic!("invalid batch!"), } @@ -355,7 +354,7 @@ mod real { } pub async fn process_task(&self, task: &mut Task) { - match self.process_task_inner(&task).await { + match self.process_task_inner(task).await { Ok(res) => task.events.push(TaskEvent::succeeded(res)), Err(e) => task.events.push(TaskEvent::failed(e)), } @@ -509,7 +508,7 @@ mod test { Self::Mock(mocker) } - pub async fn process_document_addition_batch(&self, tasks: Vec) -> Vec { + pub async fn process_document_addition_batch(&self, tasks: &mut [Task]) { match self { IndexResolver::Real(r) => r.process_document_addition_batch(tasks).await, IndexResolver::Mock(m) => unsafe { diff --git a/meilisearch-lib/src/tasks/handlers/index_resolver_handler.rs b/meilisearch-lib/src/tasks/handlers/index_resolver_handler.rs index 21751cd1c..0975ba912 100644 --- a/meilisearch-lib/src/tasks/handlers/index_resolver_handler.rs +++ b/meilisearch-lib/src/tasks/handlers/index_resolver_handler.rs @@ -19,9 +19,7 @@ where async fn process_batch(&self, mut batch: Batch) -> Batch { match batch.content { BatchContent::DocumentsAdditionBatch(ref mut tasks) => { - *tasks = self - .process_document_addition_batch(std::mem::take(tasks)) - .await; + self.process_document_addition_batch(tasks).await; } BatchContent::IndexUpdate(ref mut task) => { self.process_task(task).await; @@ -174,7 +172,7 @@ mod test { let mocker = Mocker::default(); match task.content { TaskContent::DocumentAddition { .. } => { - mocker.when::, Vec>("process_document_addition_batch").then(|tasks| tasks); + mocker.when::<&mut [Task], ()>("process_document_addition_batch").then(|_| ()); } TaskContent::Dump { .. } => (), _ => {