diff --git a/crates/index-scheduler/src/processing.rs b/crates/index-scheduler/src/processing.rs index 0bc449199..5212433ef 100644 --- a/crates/index-scheduler/src/processing.rs +++ b/crates/index-scheduler/src/processing.rs @@ -1,6 +1,9 @@ use crate::utils::ProcessingBatch; use enum_iterator::Sequence; -use meilisearch_types::milli::progress::{AtomicSubStep, NamedStep, Progress, ProgressView, Step}; +use meilisearch_types::milli::{ + make_atomic_progress, make_enum_progress, + progress::{AtomicSubStep, NamedStep, Progress, ProgressView, Step}, +}; use roaring::RoaringBitmap; use std::{borrow::Cow, sync::Arc}; @@ -55,50 +58,6 @@ impl ProcessingTasks { } } -macro_rules! make_enum_progress { - ($visibility:vis enum $name:ident { $($variant:ident,)+ }) => { - #[repr(u8)] - #[derive(Debug, Clone, Copy, PartialEq, Eq, Sequence)] - #[allow(clippy::enum_variant_names)] - $visibility enum $name { - $($variant),+ - } - - impl Step for $name { - fn name(&self) -> Cow<'static, str> { - use convert_case::Casing; - - match self { - $( - $name::$variant => stringify!($variant).from_case(convert_case::Case::Camel).to_case(convert_case::Case::Lower).into() - ),+ - } - } - - fn current(&self) -> u32 { - *self as u32 - } - - fn total(&self) -> u32 { - Self::CARDINALITY as u32 - } - } - }; -} - -macro_rules! make_atomic_progress { - ($struct_name:ident alias $atomic_struct_name:ident => $step_name:literal) => { - #[derive(Default, Debug, Clone, Copy)] - pub struct $struct_name {} - impl NamedStep for $struct_name { - fn name(&self) -> &'static str { - $step_name - } - } - pub type $atomic_struct_name = AtomicSubStep<$struct_name>; - }; -} - make_enum_progress! { pub enum BatchProgress { ProcessingTasks, diff --git a/crates/milli/src/progress.rs b/crates/milli/src/progress.rs index 63f0fbef8..40a943bd3 100644 --- a/crates/milli/src/progress.rs +++ b/crates/milli/src/progress.rs @@ -91,16 +91,53 @@ impl Step for AtomicSubStep { } } -#[derive(Default)] -pub struct Document {} +#[macro_export] +macro_rules! make_enum_progress { + ($visibility:vis enum $name:ident { $($variant:ident,)+ }) => { + #[repr(u8)] + #[derive(Debug, Clone, Copy, PartialEq, Eq, Sequence)] + #[allow(clippy::enum_variant_names)] + $visibility enum $name { + $($variant),+ + } -impl NamedStep for Document { - fn name(&self) -> &'static str { - "document" - } + impl Step for $name { + fn name(&self) -> Cow<'static, str> { + use convert_case::Casing; + + match self { + $( + $name::$variant => stringify!($variant).from_case(convert_case::Case::Camel).to_case(convert_case::Case::Lower).into() + ),+ + } + } + + fn current(&self) -> u32 { + *self as u32 + } + + fn total(&self) -> u32 { + Self::CARDINALITY as u32 + } + } + }; } -pub type AtomicDocumentStep = AtomicSubStep; +#[macro_export] +macro_rules! make_atomic_progress { + ($struct_name:ident alias $atomic_struct_name:ident => $step_name:literal) => { + #[derive(Default, Debug, Clone, Copy)] + pub struct $struct_name {} + impl NamedStep for $struct_name { + fn name(&self) -> &'static str { + $step_name + } + } + pub type $atomic_struct_name = AtomicSubStep<$struct_name>; + }; +} + +make_atomic_progress!(Document alias AtomicDocumentStep => "document" ); #[derive(Debug, Serialize, Clone)] pub struct ProgressView {