From b2c5bc67b7d7c633f1c9ce21bd42cf099fc40702 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 18 Oct 2022 11:02:46 +0200 Subject: [PATCH] Add more enum-iterator related stuff --- Cargo.lock | 1 + index-scheduler/Cargo.toml | 9 +++++---- index-scheduler/src/lib.rs | 2 +- index-scheduler/src/utils.rs | 16 +++++----------- meilisearch-auth/Cargo.toml | 2 +- meilisearch-types/Cargo.toml | 2 +- meilisearch-types/src/tasks.rs | 7 +++---- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f8cce6a1..c4484a735 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1756,6 +1756,7 @@ dependencies = [ "csv", "derive_builder", "dump", + "enum-iterator", "file-store", "insta", "log", diff --git a/index-scheduler/Cargo.toml b/index-scheduler/Cargo.toml index 95991ed43..9bfaca506 100644 --- a/index-scheduler/Cargo.toml +++ b/index-scheduler/Cargo.toml @@ -9,23 +9,24 @@ edition = "2021" anyhow = "1.0.64" bincode = "1.3.3" csv = "1.1.6" +derive_builder = "0.11.2" +dump = { path = "../dump" } +enum-iterator = "1.1.3" file-store = { path = "../file-store" } log = "0.4.14" meilisearch-types = { path = "../meilisearch-types" } roaring = { version = "0.10.0", features = ["serde"] } -dump = { path = "../dump" } serde = { version = "1.0.136", features = ["derive"] } serde_json = { version = "1.0.85", features = ["preserve_order"] } +synchronoise = "1.0.1" tempfile = "3.3.0" thiserror = "1.0.30" time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing", "macros"] } uuid = { version = "1.1.2", features = ["serde", "v4"] } -synchronoise = "1.0.1" -derive_builder = "0.11.2" [dev-dependencies] crossbeam = "0.8.2" nelson = { git = "https://github.com/meilisearch/nelson.git", rev = "675f13885548fb415ead8fbb447e9e6d9314000a"} insta = { version = "1.19.1", features = ["json", "redactions"] } big_s = "1.0.2" -meili-snap = { path = "../meili-snap" } \ No newline at end of file +meili-snap = { path = "../meili-snap" } diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index ad8b8f9e0..ba4ad24d4 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -687,7 +687,7 @@ impl IndexScheduler { | KindWithContent::IndexCreation { .. } | KindWithContent::IndexUpdate { .. } | KindWithContent::IndexSwap { .. } - | KindWithContent::CancelTask { .. } + | KindWithContent::TaskCancelation { .. } | KindWithContent::TaskDeletion { .. } | KindWithContent::DumpExport { .. } | KindWithContent::Snapshot => Ok(()), diff --git a/index-scheduler/src/utils.rs b/index-scheduler/src/utils.rs index 3183b6bc8..3e7de01ed 100644 --- a/index-scheduler/src/utils.rs +++ b/index-scheduler/src/utils.rs @@ -2,24 +2,18 @@ use meilisearch_types::heed::{types::DecodeIgnore, RoTxn, RwTxn}; use meilisearch_types::milli::BEU32; -use roaring::RoaringBitmap; +use roaring::{MultiOps, RoaringBitmap}; use crate::{Error, IndexScheduler, Result, Task, TaskId}; use meilisearch_types::tasks::{Kind, Status}; impl IndexScheduler { pub(crate) fn all_task_ids(&self, rtxn: &RoTxn) -> Result { - let mut all_tasks = RoaringBitmap::new(); - for status in [ - Status::Enqueued, - Status::Processing, - Status::Succeeded, - Status::Failed, - ] { - all_tasks |= self.get_status(&rtxn, status)?; - } - Ok(all_tasks) + enum_iterator::all() + .map(|s| self.get_status(&rtxn, s)) + .r#union() } + pub(crate) fn last_task_id(&self, rtxn: &RoTxn) -> Result> { Ok(self .all_tasks diff --git a/meilisearch-auth/Cargo.toml b/meilisearch-auth/Cargo.toml index f8c851ff4..e673c2f9a 100644 --- a/meilisearch-auth/Cargo.toml +++ b/meilisearch-auth/Cargo.toml @@ -8,10 +8,10 @@ enum-iterator = "1.1.3" hmac = "0.12.1" meilisearch-types = { path = "../meilisearch-types" } rand = "0.8.5" +roaring = { version = "0.10.0", features = ["serde"] } serde = { version = "1.0.145", features = ["derive"] } serde_json = { version = "1.0.85", features = ["preserve_order"] } sha2 = "0.10.6" thiserror = "1.0.37" time = { version = "0.3.15", features = ["serde-well-known", "formatting", "parsing", "macros"] } uuid = { version = "1.1.2", features = ["serde", "v4"] } -roaring = { version = "0.10.0", features = ["serde"] } diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index 5b3aa79d8..e731ed3f3 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -16,8 +16,8 @@ proptest-derive = { version = "0.3.0", optional = true } roaring = { version = "0.10.0", features = ["serde"] } serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.85" -time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing", "macros"] } thiserror = "1.0.30" +time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing", "macros"] } tokio = "1.0" uuid = { version = "1.1.2", features = ["serde", "v4"] } diff --git a/meilisearch-types/src/tasks.rs b/meilisearch-types/src/tasks.rs index 3d32f385e..901250dd2 100644 --- a/meilisearch-types/src/tasks.rs +++ b/meilisearch-types/src/tasks.rs @@ -1,11 +1,10 @@ +use std::fmt::{Display, Write}; +use std::str::FromStr; + use enum_iterator::Sequence; use milli::update::IndexDocumentsMethod; use roaring::RoaringBitmap; use serde::{Deserialize, Serialize, Serializer}; -use std::{ - fmt::{Display, Write}, - str::FromStr, -}; use time::{Duration, OffsetDateTime}; use uuid::Uuid;