diff --git a/src/graphql/outlier.rs b/src/graphql/outlier.rs index 561935fb..220c55b2 100644 --- a/src/graphql/outlier.rs +++ b/src/graphql/outlier.rs @@ -55,16 +55,24 @@ impl OutlierMutation { #[derive(Default)] pub(super) struct OutlierQuery; +#[allow(clippy::module_name_repetitions)] #[derive(InputObject, Serialize)] pub struct OutlierTimeRange { start: Option>, end: Option>, } +#[allow(clippy::module_name_repetitions)] +#[derive(InputObject, Serialize)] +pub struct OutlierDistanceRange { + start: Option, + end: Option, +} + #[derive(InputObject, Serialize)] pub struct SearchFilterInput { pub time: Option, - distance: Option, + distance: Option, } #[Object] @@ -602,6 +610,7 @@ fn latest_outlier_key(before: &str) -> Result> { Ok(end) } +#[allow(clippy::too_many_arguments, clippy::type_complexity)] // since this is called within `load` only async fn load_ranked_outliers_with_filter( ctx: &Context<'_>, model_id: ID, @@ -663,9 +672,9 @@ where let (nodes, has_more) = if let Some(after) = after { let to = earliest_key(&after)?; - iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_ge, &filter, last) + iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_ge, filter, last) } else { - iter_through_search_filter_nodes(iter, &[], always_true, &filter, last) + iter_through_search_filter_nodes(iter, &[], always_true, filter, last) }?; Ok((nodes, has_more, false)) } else { @@ -679,9 +688,9 @@ where let (nodes, has_more) = if let Some(before) = before { let to = latest_key(&before)?; - iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_le, &filter, first) + iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_le, filter, first) } else { - iter_through_search_filter_nodes(iter, &[], always_true, &filter, first) + iter_through_search_filter_nodes(iter, &[], always_true, filter, first) }?; Ok((nodes, false, has_more)) } @@ -720,23 +729,27 @@ where { continue; } - } else { - if node.timestamp < start.timestamp_nanos_opt().unwrap_or_default() { - continue; - } + } else if node.timestamp < start.timestamp_nanos_opt().unwrap_or_default() { + continue; } - } else { - if let Some(end) = end { - if node.timestamp > end.timestamp_nanos_opt().unwrap_or_default() { - continue; - } + } else if let Some(end) = end { + if node.timestamp > end.timestamp_nanos_opt().unwrap_or_default() { + continue; } } } - if let Some(distance) = filter.distance { - if node.distance != distance { - continue; + if let Some(distance) = &filter.distance { + let start = distance.start; + let end = distance.end; + if let Some(start) = start { + if let Some(end) = end { + if node.distance < start || node.distance > end { + continue; + } + } else if (((node.distance * 10.0).round() / 10.0) - start).abs() > 0.0 { + continue; + } } } }