Refactorize the tasks filters by moving the match inside

This commit is contained in:
Kerollmops 2022-05-30 17:38:25 +02:00
parent 8800b348f0
commit 1465b5e0ff
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -137,39 +137,28 @@ async fn get_tasks(
}; };
// Then we complete the task filter with other potential status and types filters. // Then we complete the task filter with other potential status and types filters.
let filters = match (type_, status) { let filters = if type_.is_some() || status.is_some() {
(Some(types), Some(statuses)) => { let mut filters = indexes_filters.unwrap_or_default();
let mut filters = indexes_filters.unwrap_or_default(); filters.filter_fn(move |task| {
filters.filter_fn(move |task| { let matches_type = match &type_ {
let matches_type = types Some(types) => types
.iter() .iter()
.any(|t| task_type_matches_content(t, &task.content)); .any(|t| task_type_matches_content(t, &task.content)),
let matches_status = statuses None => true,
};
let matches_status = match &status {
Some(statuses) => statuses
.iter() .iter()
.any(|s| task_status_matches_events(s, &task.events)); .any(|t| task_status_matches_events(t, &task.events)),
matches_type && matches_status None => true,
}); };
Some(filters)
} matches_type && matches_status
(Some(types), None) => { });
let mut filters = indexes_filters.unwrap_or_default(); Some(filters)
filters.filter_fn(move |task| { } else {
types indexes_filters
.iter()
.any(|t| task_type_matches_content(t, &task.content))
});
Some(filters)
}
(None, Some(statuses)) => {
let mut filters = indexes_filters.unwrap_or_default();
filters.filter_fn(move |task| {
statuses
.iter()
.any(|s| task_status_matches_events(s, &task.events))
});
Some(filters)
}
(None, None) => indexes_filters,
}; };
let tasks: TaskListView = meilisearch let tasks: TaskListView = meilisearch