From 72b2e68de4ee4884a072968cb8b2847786937d95 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 7 Sep 2022 20:44:33 +0200 Subject: [PATCH] makes the updates getters smoother to uses --- index-scheduler/src/lib.rs | 13 ++++--------- index-scheduler/src/utils.rs | 30 +++++++++++++----------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index a8605ca3d..0706c73b6 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -169,21 +169,16 @@ impl IndexScheduler { if let Some(indexes) = task.indexes() { for index in indexes { - self.update_index(&mut wtxn, index, |mut bitmap| { - bitmap.insert(task_id); - bitmap - })?; + self.update_index(&mut wtxn, index, |bitmap| drop(bitmap.insert(task_id)))?; } } - self.update_status(&mut wtxn, Status::Enqueued, |mut bitmap| { + self.update_status(&mut wtxn, Status::Enqueued, |bitmap| { bitmap.insert(task_id); - bitmap })?; - self.update_kind(&mut wtxn, task.kind.as_kind(), |mut bitmap| { - bitmap.insert(task_id); - bitmap + self.update_kind(&mut wtxn, task.kind.as_kind(), |bitmap| { + (bitmap.insert(task_id)); })?; // we persist the file in last to be sure everything before was applied successfuly diff --git a/index-scheduler/src/utils.rs b/index-scheduler/src/utils.rs index 0efcdba2d..99190e086 100644 --- a/index-scheduler/src/utils.rs +++ b/index-scheduler/src/utils.rs @@ -50,24 +50,20 @@ impl IndexScheduler { .ok_or(Error::CorruptedTaskQueue)?; if old_task.status != task.status { - self.update_status(wtxn, old_task.status, |mut bitmap| { + self.update_status(wtxn, old_task.status, |bitmap| { bitmap.remove(task.uid); - bitmap })?; - self.update_status(wtxn, task.status, |mut bitmap| { + self.update_status(wtxn, task.status, |bitmap| { bitmap.insert(task.uid); - bitmap })?; } if old_task.kind.as_kind() != task.kind.as_kind() { - self.update_kind(wtxn, old_task.kind.as_kind(), |mut bitmap| { + self.update_kind(wtxn, old_task.kind.as_kind(), |bitmap| { bitmap.remove(task.uid); - bitmap })?; - self.update_kind(wtxn, task.kind.as_kind(), |mut bitmap| { + self.update_kind(wtxn, task.kind.as_kind(), |bitmap| { bitmap.insert(task.uid); - bitmap })?; } @@ -91,10 +87,10 @@ impl IndexScheduler { &self, wtxn: &mut RwTxn, index: &str, - f: impl Fn(RoaringBitmap) -> RoaringBitmap, + f: impl Fn(&mut RoaringBitmap), ) -> Result<()> { - let tasks = self.get_index(&wtxn, index)?; - let tasks = f(tasks); + let mut tasks = self.get_index(&wtxn, index)?; + f(&mut tasks); self.put_index(wtxn, index, &tasks)?; Ok(()) @@ -117,10 +113,10 @@ impl IndexScheduler { &self, wtxn: &mut RwTxn, status: Status, - f: impl Fn(RoaringBitmap) -> RoaringBitmap, + f: impl Fn(&mut RoaringBitmap), ) -> Result<()> { - let tasks = self.get_status(&wtxn, status)?; - let tasks = f(tasks); + let mut tasks = self.get_status(&wtxn, status)?; + f(&mut tasks); self.put_status(wtxn, status, &tasks)?; Ok(()) @@ -143,10 +139,10 @@ impl IndexScheduler { &self, wtxn: &mut RwTxn, kind: Kind, - f: impl Fn(RoaringBitmap) -> RoaringBitmap, + f: impl Fn(&mut RoaringBitmap), ) -> Result<()> { - let tasks = self.get_kind(&wtxn, kind)?; - let tasks = f(tasks); + let mut tasks = self.get_kind(&wtxn, kind)?; + f(&mut tasks); self.put_kind(wtxn, kind, &tasks)?; Ok(())