From e9055f55725326bb66470d6f0a8394289ed12e21 Mon Sep 17 00:00:00 2001 From: Irevoire Date: Sat, 22 Oct 2022 16:35:42 +0200 Subject: [PATCH] fix clippy --- dump/src/lib.rs | 7 +++-- dump/src/reader/compat/v3_to_v4.rs | 4 +-- dump/src/reader/compat/v5_to_v6.rs | 22 ++++++------- dump/src/reader/mod.rs | 4 +-- dump/src/reader/v2/mod.rs | 8 ++--- dump/src/reader/v3/mod.rs | 4 +-- dump/src/reader/v3/settings.rs | 2 +- dump/src/reader/v4/mod.rs | 4 +-- dump/src/reader/v4/settings.rs | 12 +++---- dump/src/reader/v4/tasks.rs | 4 +-- dump/src/reader/v5/mod.rs | 4 +-- dump/src/reader/v5/settings.rs | 12 +++---- dump/src/reader/v5/tasks.rs | 4 +-- dump/src/reader/v6/mod.rs | 2 +- dump/src/writer.rs | 6 ++-- index-scheduler/src/autobatcher.rs | 4 +-- index-scheduler/src/batch.rs | 18 +++++------ index-scheduler/src/error.rs | 1 + index-scheduler/src/index_mapper.rs | 1 + index-scheduler/src/lib.rs | 5 +-- index-scheduler/src/snapshot.rs | 28 +++++++++-------- index-scheduler/src/utils.rs | 17 +++++----- meili-snap/src/lib.rs | 4 +-- meilisearch-http/src/lib.rs | 31 +++++++++---------- meilisearch-http/src/main.rs | 2 +- .../src/routes/indexes/documents.rs | 2 +- .../src/routes/indexes/settings.rs | 10 +++--- meilisearch-http/src/routes/mod.rs | 4 +-- meilisearch-http/src/routes/tasks.rs | 10 +++--- meilisearch-http/src/search.rs | 8 ++--- meilisearch-types/src/tasks.rs | 5 ++- 31 files changed, 125 insertions(+), 124 deletions(-) diff --git a/dump/src/lib.rs b/dump/src/lib.rs index b1ce673c3..772825bdd 100644 --- a/dump/src/lib.rs +++ b/dump/src/lib.rs @@ -1,3 +1,6 @@ +#![allow(clippy::type_complexity)] +#![allow(clippy::wrong_self_convention)] + use meilisearch_types::error::ResponseError; use meilisearch_types::keys::Key; use meilisearch_types::milli::update::IndexDocumentsMethod; @@ -99,7 +102,7 @@ pub enum KindDump { }, DocumentClear, Settings { - settings: meilisearch_types::settings::Settings, + settings: Box>, is_deletion: bool, allow_index_creation: bool, }, @@ -369,7 +372,7 @@ pub(crate) mod test { pub fn create_test_dump() -> File { let instance_uid = create_test_instance_uid(); - let dump = DumpWriter::new(Some(instance_uid.clone())).unwrap(); + let dump = DumpWriter::new(Some(instance_uid)).unwrap(); // ========== Adding an index let documents = create_test_documents(); diff --git a/dump/src/reader/compat/v3_to_v4.rs b/dump/src/reader/compat/v3_to_v4.rs index b1d7dbd66..c12aeba78 100644 --- a/dump/src/reader/compat/v3_to_v4.rs +++ b/dump/src/reader/compat/v3_to_v4.rs @@ -74,7 +74,7 @@ impl CompatV3ToV4 { .map(|index| index.uid.clone()); let index_uid = match index_uid { - Some(uid) => uid.to_string(), + Some(uid) => uid, None => { log::warn!( "Error while importing the update {}.", @@ -120,7 +120,7 @@ impl CompatV3ToV4 { primary_key: primary_key.clone(), documents_count: 0, // we don't have this info allow_index_creation: true, // there was no API-key in the v3 - content_uuid: content_uuid.clone(), + content_uuid: *content_uuid, }, v3::Kind::Settings(settings) => { v4::tasks::TaskContent::SettingsUpdate { diff --git a/dump/src/reader/compat/v5_to_v6.rs b/dump/src/reader/compat/v5_to_v6.rs index 42cac3c9c..ed874d3ff 100644 --- a/dump/src/reader/compat/v5_to_v6.rs +++ b/dump/src/reader/compat/v5_to_v6.rs @@ -51,7 +51,7 @@ impl CompatV5ToV6 { pub fn tasks( &mut self, ) -> Result>)>> + '_>> { - let instance_uid = self.instance_uid().ok().flatten().map(|uid| uid.clone()); + let instance_uid = self.instance_uid().ok().flatten(); let keys = self.keys()?.collect::>>()?; let tasks = match self { @@ -59,7 +59,7 @@ impl CompatV5ToV6 { CompatV5ToV6::Compat(compat) => compat.tasks(), }; Ok(Box::new(tasks.map(move |task| { - task.and_then(|(task, content_file)| { + task.map(|(task, content_file)| { let mut task_view: v5::tasks::TaskView = task.clone().into(); if task_view.status == v5::Status::Processing { @@ -75,7 +75,7 @@ impl CompatV5ToV6 { v5::Status::Succeeded => v6::Status::Succeeded, v5::Status::Failed => v6::Status::Failed, }, - kind: match task.content.clone() { + kind: match task.content { v5::tasks::TaskContent::IndexCreation { primary_key, .. } => { v6::Kind::IndexCreation { primary_key } } @@ -100,7 +100,7 @@ impl CompatV5ToV6 { v6::milli::update::IndexDocumentsMethod::UpdateDocuments } }, - allow_index_creation: allow_index_creation.clone(), + allow_index_creation, }, v5::tasks::TaskContent::DocumentDeletion { deletion, .. } => match deletion { @@ -117,13 +117,11 @@ impl CompatV5ToV6 { } => v6::Kind::Settings { is_deletion, allow_index_creation, - settings: settings.into(), - }, - v5::tasks::TaskContent::Dump { uid } => v6::Kind::DumpExport { - dump_uid: uid, - keys: keys.clone(), - instance_uid: instance_uid.clone(), + settings: Box::new(settings.into()), }, + v5::tasks::TaskContent::Dump { uid } => { + v6::Kind::DumpExport { dump_uid: uid, keys: keys.clone(), instance_uid } + } }, canceled_by: None, details: task_view.details.map(|details| match details { @@ -134,7 +132,7 @@ impl CompatV5ToV6 { } } v5::Details::Settings { settings } => { - v6::Details::SettingsUpdate { settings: settings.into() } + v6::Details::SettingsUpdate { settings: Box::new(settings.into()) } } v5::Details::IndexInfo { primary_key } => { v6::Details::IndexInfo { primary_key } @@ -157,7 +155,7 @@ impl CompatV5ToV6 { finished_at: task_view.finished_at, }; - Ok((task, content_file)) + (task, content_file) }) }))) } diff --git a/dump/src/reader/mod.rs b/dump/src/reader/mod.rs index 2dbd8c51a..a73b843f2 100644 --- a/dump/src/reader/mod.rs +++ b/dump/src/reader/mod.rs @@ -134,7 +134,7 @@ impl From for DumpReader { pub enum DumpIndexReader { Current(v6::V6IndexReader), - Compat(CompatIndexV5ToV6), + Compat(Box), } impl DumpIndexReader { @@ -176,7 +176,7 @@ impl From for DumpIndexReader { impl From for DumpIndexReader { fn from(value: CompatIndexV5ToV6) -> Self { - DumpIndexReader::Compat(value) + DumpIndexReader::Compat(Box::new(value)) } } diff --git a/dump/src/reader/v2/mod.rs b/dump/src/reader/v2/mod.rs index b9275c988..b311c5f14 100644 --- a/dump/src/reader/v2/mod.rs +++ b/dump/src/reader/v2/mod.rs @@ -105,10 +105,10 @@ impl V2Reader { pub fn indexes(&self) -> Result> + '_> { Ok(self.index_uuid.iter().map(|index| -> Result<_> { - Ok(V2IndexReader::new( + V2IndexReader::new( index.uid.clone(), - &self.dump.path().join("indexes").join(format!("index-{}", index.uuid.to_string())), - )?) + &self.dump.path().join("indexes").join(format!("index-{}", index.uuid)), + ) })) } @@ -122,7 +122,7 @@ impl V2Reader { .path() .join("updates") .join("update_files") - .join(format!("update_{}", uuid.to_string())); + .join(format!("update_{}", uuid)); Ok((task, Some(UpdateFile::new(&update_file_path)?))) } else { Ok((task, None)) diff --git a/dump/src/reader/v3/mod.rs b/dump/src/reader/v3/mod.rs index 96dd0ccf5..9438aa1a3 100644 --- a/dump/src/reader/v3/mod.rs +++ b/dump/src/reader/v3/mod.rs @@ -111,10 +111,10 @@ impl V3Reader { pub fn indexes(&self) -> Result> + '_> { Ok(self.index_uuid.iter().map(|index| -> Result<_> { - Ok(V3IndexReader::new( + V3IndexReader::new( index.uid.clone(), &self.dump.path().join("indexes").join(index.uuid.to_string()), - )?) + ) })) } diff --git a/dump/src/reader/v3/settings.rs b/dump/src/reader/v3/settings.rs index 644ad4cb6..0027bf4ff 100644 --- a/dump/src/reader/v3/settings.rs +++ b/dump/src/reader/v3/settings.rs @@ -160,7 +160,7 @@ pub struct Facets { pub min_level_size: Option, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Setting { Set(T), Reset, diff --git a/dump/src/reader/v4/mod.rs b/dump/src/reader/v4/mod.rs index 718291ad0..32340fba5 100644 --- a/dump/src/reader/v4/mod.rs +++ b/dump/src/reader/v4/mod.rs @@ -97,10 +97,10 @@ impl V4Reader { pub fn indexes(&self) -> Result> + '_> { Ok(self.index_uuid.iter().map(|index| -> Result<_> { - Ok(V4IndexReader::new( + V4IndexReader::new( index.uid.clone(), &self.dump.path().join("indexes").join(index.index_meta.uuid.to_string()), - )?) + ) })) } diff --git a/dump/src/reader/v4/settings.rs b/dump/src/reader/v4/settings.rs index 7ca79a8f4..964cd1152 100644 --- a/dump/src/reader/v4/settings.rs +++ b/dump/src/reader/v4/settings.rs @@ -23,15 +23,15 @@ where .serialize(s) } -#[derive(Clone, Default, Debug, PartialEq)] +#[derive(Clone, Default, Debug, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] pub struct Checked; -#[derive(Clone, Default, Debug, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] pub struct Unchecked; -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] @@ -42,7 +42,7 @@ pub struct MinWordSizeTyposSetting { pub two_typos: Setting, } -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] @@ -59,7 +59,7 @@ pub struct TypoSettings { /// Holds all the settings for an index. `T` can either be `Checked` if they represents settings /// whose validity is guaranteed, or `Unchecked` if they need to be validated. In the later case, a /// call to `check` will return a `Settings` from a `Settings`. -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] @@ -191,7 +191,7 @@ pub struct Facets { pub min_level_size: Option, } -#[derive(Debug, Clone, PartialEq, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, Copy)] pub enum Setting { Set(T), Reset, diff --git a/dump/src/reader/v4/tasks.rs b/dump/src/reader/v4/tasks.rs index 7a734deab..e1bdde0c7 100644 --- a/dump/src/reader/v4/tasks.rs +++ b/dump/src/reader/v4/tasks.rs @@ -9,7 +9,7 @@ use super::settings::{Settings, Unchecked}; pub type TaskId = u32; pub type BatchId = u32; -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] pub struct Task { pub id: TaskId, @@ -18,7 +18,7 @@ pub struct Task { pub events: Vec, } -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[allow(clippy::large_enum_variant)] pub enum TaskContent { diff --git a/dump/src/reader/v5/mod.rs b/dump/src/reader/v5/mod.rs index 930cee4a9..16ad20781 100644 --- a/dump/src/reader/v5/mod.rs +++ b/dump/src/reader/v5/mod.rs @@ -138,10 +138,10 @@ impl V5Reader { pub fn indexes(&self) -> Result> + '_> { Ok(self.index_uuid.iter().map(|index| -> Result<_> { - Ok(V5IndexReader::new( + V5IndexReader::new( index.uid.clone(), &self.dump.path().join("indexes").join(index.index_meta.uuid.to_string()), - )?) + ) })) } diff --git a/dump/src/reader/v5/settings.rs b/dump/src/reader/v5/settings.rs index d74ef4d1c..9a542149f 100644 --- a/dump/src/reader/v5/settings.rs +++ b/dump/src/reader/v5/settings.rs @@ -12,7 +12,7 @@ pub struct Unchecked; /// Holds all the settings for an index. `T` can either be `Checked` if they represents settings /// whose validity is guaranteed, or `Unchecked` if they need to be validated. In the later case, a /// call to `check` will return a `Settings` from a `Settings`. -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] @@ -47,7 +47,7 @@ pub struct Settings { pub _kind: PhantomData, } -#[derive(Debug, Clone, PartialEq, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, Copy)] #[cfg_attr(test, derive(serde::Serialize))] pub enum Setting { Set(T), @@ -102,7 +102,7 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Setting { } } -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] @@ -113,7 +113,7 @@ pub struct MinWordSizeTyposSetting { pub two_typos: Setting, } -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] @@ -128,7 +128,7 @@ pub struct TypoSettings { pub disable_on_attributes: Setting>, } -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] @@ -137,7 +137,7 @@ pub struct FacetingSettings { pub max_values_per_facet: Setting, } -#[derive(Debug, Clone, Default, Deserialize, PartialEq)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] diff --git a/dump/src/reader/v5/tasks.rs b/dump/src/reader/v5/tasks.rs index d3fe2010c..125e20559 100644 --- a/dump/src/reader/v5/tasks.rs +++ b/dump/src/reader/v5/tasks.rs @@ -9,7 +9,7 @@ use super::settings::{Settings, Unchecked}; pub type TaskId = u32; pub type BatchId = u32; -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] pub struct Task { pub id: TaskId, @@ -21,7 +21,7 @@ pub struct Task { pub events: Vec, } -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] #[cfg_attr(test, derive(serde::Serialize))] #[allow(clippy::large_enum_variant)] pub enum TaskContent { diff --git a/dump/src/reader/v6/mod.rs b/dump/src/reader/v6/mod.rs index f4af70c1d..4b08c6f8d 100644 --- a/dump/src/reader/v6/mod.rs +++ b/dump/src/reader/v6/mod.rs @@ -108,7 +108,7 @@ impl V6Reader { .path() .join("tasks") .join("update_files") - .join(format!("{}.jsonl", task.uid.to_string())); + .join(format!("{}.jsonl", task.uid)); if update_file_path.exists() { Ok(( diff --git a/dump/src/writer.rs b/dump/src/writer.rs index db233c4b4..b49da974b 100644 --- a/dump/src/writer.rs +++ b/dump/src/writer.rs @@ -233,13 +233,13 @@ pub(crate) mod test { let mut ident = String::new(); for _ in 0..depth { - ident.push_str(&"│"); + ident.push('│'); ident.push_str(&" ".repeat(4)); } if idx == entries.len() - 1 { - ident.push_str(&"└"); + ident.push('└'); } else { - ident.push_str(&"├"); + ident.push('├'); } ident.push_str(&"-".repeat(4)); diff --git a/index-scheduler/src/autobatcher.rs b/index-scheduler/src/autobatcher.rs index d5860f67b..ad27b50ee 100644 --- a/index-scheduler/src/autobatcher.rs +++ b/index-scheduler/src/autobatcher.rs @@ -170,7 +170,7 @@ impl BatchKind { // We don't batch any of these operations (this, K::IndexCreation | K::IndexUpdate | K::IndexSwap) => Break(this), // We must not batch tasks that don't have the same index creation rights if the index doesn't already exists. - (this, kind) if index_already_exists == false && this.allow_index_creation() == Some(false) && kind.allow_index_creation() == Some(true) => { + (this, kind) if !index_already_exists && this.allow_index_creation() == Some(false) && kind.allow_index_creation() == Some(true) => { Break(this) }, // The index deletion can batch with everything but must stop after @@ -443,7 +443,7 @@ mod tests { input: impl IntoIterator, ) -> Option<(BatchKind, bool)> { autobatch( - input.into_iter().enumerate().map(|(id, kind)| (id as TaskId, kind.into())).collect(), + input.into_iter().enumerate().map(|(id, kind)| (id as TaskId, kind)).collect(), index_already_exists, ) } diff --git a/index-scheduler/src/batch.rs b/index-scheduler/src/batch.rs index cb12ecefa..42c3a7867 100644 --- a/index-scheduler/src/batch.rs +++ b/index-scheduler/src/batch.rs @@ -242,7 +242,7 @@ impl IndexScheduler { match task.kind { KindWithContent::SettingsUpdate { ref new_settings, is_deletion, .. - } => settings.push((is_deletion, new_settings.clone())), + } => settings.push((is_deletion, *new_settings.clone())), _ => unreachable!(), } } @@ -424,7 +424,7 @@ impl IndexScheduler { // AT LEAST one index. We can use the right or left one it doesn't // matter. let index_name = task.indexes().unwrap()[0]; - let index_already_exists = self.index_mapper.exists(rtxn, &index_name)?; + let index_already_exists = self.index_mapper.exists(rtxn, index_name)?; let index_tasks = self.index_tasks(rtxn, index_name)? & enqueued; @@ -550,7 +550,7 @@ impl IndexScheduler { } else { unreachable!(); }; - let dump = dump::DumpWriter::new(instance_uid.clone())?; + let dump = dump::DumpWriter::new(*instance_uid)?; // 1. dump the keys let mut dump_keys = dump.create_keys()?; @@ -566,7 +566,7 @@ impl IndexScheduler { for ret in self.all_tasks.iter(&rtxn)? { let (_, mut t) = ret?; let status = t.status; - let content_file = t.content_uuid().map(|uuid| uuid.clone()); + let content_file = t.content_uuid().copied(); // In the case we're dumping ourselves we want to be marked as finished // to not loop over ourselves indefinitely. @@ -745,11 +745,11 @@ impl IndexScheduler { /// Swap the index `lhs` with the index `rhs`. fn apply_index_swap(&self, wtxn: &mut RwTxn, task_id: u32, lhs: &str, rhs: &str) -> Result<()> { // 1. Verify that both lhs and rhs are existing indexes - let index_lhs_exists = self.index_mapper.index_exists(&wtxn, lhs)?; + let index_lhs_exists = self.index_mapper.index_exists(wtxn, lhs)?; if !index_lhs_exists { return Err(Error::IndexNotFound(lhs.to_owned())); } - let index_rhs_exists = self.index_mapper.index_exists(&wtxn, rhs)?; + let index_rhs_exists = self.index_mapper.index_exists(wtxn, rhs)?; if !index_rhs_exists { return Err(Error::IndexNotFound(rhs.to_owned())); } @@ -764,7 +764,7 @@ impl IndexScheduler { // 3. before_name -> new_name in the task's KindWithContent for task_id in &index_lhs_task_ids | &index_rhs_task_ids { - let mut task = self.get_task(&wtxn, task_id)?.ok_or(Error::CorruptedTaskQueue)?; + let mut task = self.get_task(wtxn, task_id)?.ok_or(Error::CorruptedTaskQueue)?; swap_index_uid_in_task(&mut task, (lhs, rhs)); self.all_tasks.put(wtxn, &BEU32::new(task_id), &task)?; } @@ -934,7 +934,7 @@ impl IndexScheduler { // TODO merge the settings to only do *one* reindexation. for (task, (_, settings)) in tasks.iter_mut().zip(settings) { let checked_settings = settings.clone().check(); - task.details = Some(Details::SettingsUpdate { settings }); + task.details = Some(Details::SettingsUpdate { settings: Box::new(settings) }); let mut builder = milli::update::Settings::new(index_wtxn, index, indexer_config); @@ -1023,7 +1023,7 @@ impl IndexScheduler { let enqueued_tasks = self.get_status(wtxn, Status::Enqueued)?; let processing_tasks = &self.processing_tasks.read().unwrap().processing.clone(); - let all_task_ids = self.all_task_ids(&wtxn)?; + let all_task_ids = self.all_task_ids(wtxn)?; let mut to_delete_tasks = all_task_ids & matched_tasks; to_delete_tasks -= processing_tasks; to_delete_tasks -= enqueued_tasks; diff --git a/index-scheduler/src/error.rs b/index-scheduler/src/error.rs index a4e94c663..caa5539d8 100644 --- a/index-scheduler/src/error.rs +++ b/index-scheduler/src/error.rs @@ -4,6 +4,7 @@ use thiserror::Error; use crate::TaskId; +#[allow(clippy::large_enum_variant)] #[derive(Error, Debug)] pub enum Error { #[error("Index `{0}` not found.")] diff --git a/index-scheduler/src/index_mapper.rs b/index-scheduler/src/index_mapper.rs index 55bb4476f..9b8ba5676 100644 --- a/index-scheduler/src/index_mapper.rs +++ b/index-scheduler/src/index_mapper.rs @@ -39,6 +39,7 @@ pub struct IndexMapper { } /// Whether the index is available for use or is forbidden to be inserted back in the index map +#[allow(clippy::large_enum_variant)] #[derive(Clone)] pub enum IndexStatus { /// Do not insert it back in the index map as it is currently being deleted. diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index f794a45b8..66f9917c7 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -267,6 +267,7 @@ impl IndexScheduler { /// - `indexer_config`: configuration used during indexing for each meilisearch index /// - `autobatching_enabled`: `true` iff the index scheduler is allowed to automatically batch tasks /// together, to process multiple tasks at once. + #[allow(clippy::too_many_arguments)] pub fn new( tasks_path: PathBuf, update_file_path: PathBuf, @@ -401,7 +402,7 @@ impl IndexScheduler { if let Some(index) = &query.index_uid { let mut index_tasks = RoaringBitmap::new(); for index in index { - index_tasks |= self.index_tasks(&rtxn, &index)?; + index_tasks |= self.index_tasks(&rtxn, index)?; } tasks &= index_tasks; } @@ -793,7 +794,7 @@ mod tests { primary_key: primary_key.map(ToOwned::to_owned), method: ReplaceDocuments, content_file: Uuid::from_u128(content_file_uuid), - documents_count: documents_count, + documents_count, allow_index_creation: true, } } diff --git a/index-scheduler/src/snapshot.rs b/index-scheduler/src/snapshot.rs index 60831be1e..40a43ffd8 100644 --- a/index-scheduler/src/snapshot.rs +++ b/index-scheduler/src/snapshot.rs @@ -1,3 +1,5 @@ +use std::fmt::Write; + use meilisearch_types::heed::types::{OwnedType, SerdeBincode, SerdeJson, Str}; use meilisearch_types::heed::{Database, RoTxn}; use meilisearch_types::milli::{CboRoaringBitmapCodec, RoaringBitmapCodec, BEU32}; @@ -96,8 +98,8 @@ fn snapshot_bitmap(r: &RoaringBitmap) -> String { fn snapshot_all_tasks(rtxn: &RoTxn, db: Database, SerdeJson>) -> String { let mut snap = String::new(); - let mut iter = db.iter(rtxn).unwrap(); - while let Some(next) = iter.next() { + let iter = db.iter(rtxn).unwrap(); + for next in iter { let (task_id, task) = next.unwrap(); snap.push_str(&format!("{task_id} {}\n", snapshot_task(&task))); } @@ -109,8 +111,8 @@ fn snapshot_date_db( db: Database, CboRoaringBitmapCodec>, ) -> String { let mut snap = String::new(); - let mut iter = db.iter(rtxn).unwrap(); - while let Some(next) = iter.next() { + let iter = db.iter(rtxn).unwrap(); + for next in iter { let (_timestamp, task_ids) = next.unwrap(); snap.push_str(&format!("[timestamp] {}\n", snapshot_bitmap(&task_ids))); } @@ -191,31 +193,31 @@ fn snaphsot_details(d: &Details) -> String { fn snapshot_status(rtxn: &RoTxn, db: Database, RoaringBitmapCodec>) -> String { let mut snap = String::new(); - let mut iter = db.iter(rtxn).unwrap(); - while let Some(next) = iter.next() { + let iter = db.iter(rtxn).unwrap(); + for next in iter { let (status, task_ids) = next.unwrap(); - snap.push_str(&format!("{status} {}\n", snapshot_bitmap(&task_ids))); + write!(snap, "{status} {}\n", snapshot_bitmap(&task_ids)).unwrap(); } snap } fn snapshot_kind(rtxn: &RoTxn, db: Database, RoaringBitmapCodec>) -> String { let mut snap = String::new(); - let mut iter = db.iter(rtxn).unwrap(); - while let Some(next) = iter.next() { + let iter = db.iter(rtxn).unwrap(); + for next in iter { let (kind, task_ids) = next.unwrap(); let kind = serde_json::to_string(&kind).unwrap(); - snap.push_str(&format!("{kind} {}\n", snapshot_bitmap(&task_ids))); + write!(snap, "{kind} {}\n", snapshot_bitmap(&task_ids)).unwrap(); } snap } fn snapshot_index_tasks(rtxn: &RoTxn, db: Database) -> String { let mut snap = String::new(); - let mut iter = db.iter(rtxn).unwrap(); - while let Some(next) = iter.next() { + let iter = db.iter(rtxn).unwrap(); + for next in iter { let (index, task_ids) = next.unwrap(); - snap.push_str(&format!("{index} {}\n", snapshot_bitmap(&task_ids))); + write!(snap, "{index} {}\n", snapshot_bitmap(&task_ids)).unwrap(); } snap } diff --git a/index-scheduler/src/utils.rs b/index-scheduler/src/utils.rs index 8a0d00d2a..007c0c065 100644 --- a/index-scheduler/src/utils.rs +++ b/index-scheduler/src/utils.rs @@ -13,7 +13,7 @@ use crate::{Error, IndexScheduler, Result, Task, TaskId, BEI128}; impl IndexScheduler { pub(crate) fn all_task_ids(&self, rtxn: &RoTxn) -> Result { - enum_iterator::all().map(|s| self.get_status(&rtxn, s)).union() + enum_iterator::all().map(|s| self.get_status(rtxn, s)).union() } pub(crate) fn last_task_id(&self, rtxn: &RoTxn) -> Result> { @@ -173,7 +173,7 @@ pub(crate) fn insert_task_datetime( task_id: TaskId, ) -> Result<()> { let timestamp = BEI128::new(time.unix_timestamp_nanos()); - let mut task_ids = database.get(&wtxn, ×tamp)?.unwrap_or_default(); + let mut task_ids = database.get(wtxn, ×tamp)?.unwrap_or_default(); task_ids.insert(task_id); database.put(wtxn, ×tamp, &RoaringBitmap::from_iter([task_id]))?; Ok(()) @@ -186,7 +186,7 @@ pub(crate) fn remove_task_datetime( task_id: TaskId, ) -> Result<()> { let timestamp = BEI128::new(time.unix_timestamp_nanos()); - if let Some(mut existing) = database.get(&wtxn, ×tamp)? { + if let Some(mut existing) = database.get(wtxn, ×tamp)? { existing.remove(task_id); if existing.is_empty() { database.delete(wtxn, ×tamp)?; @@ -214,7 +214,7 @@ pub(crate) fn keep_tasks_within_datetimes( let mut collected_task_ids = RoaringBitmap::new(); let start = map_bound(start, |b| BEI128::new(b.unix_timestamp_nanos())); let end = map_bound(end, |b| BEI128::new(b.unix_timestamp_nanos())); - let iter = database.range(&rtxn, &(start, end))?; + let iter = database.range(rtxn, &(start, end))?; for r in iter { let (_timestamp, task_ids) = r?; collected_task_ids |= task_ids; @@ -245,22 +245,21 @@ pub fn swap_index_uid_in_task(task: &mut Task, swap: (&str, &str)) { K::IndexUpdate { index_uid, .. } => index_uids.push(index_uid), K::IndexSwap { swaps } => { for (lhs, rhs) in swaps.iter_mut() { - if lhs == &swap.0 || lhs == &swap.1 { + if lhs == swap.0 || lhs == swap.1 { index_uids.push(lhs); } - if rhs == &swap.0 || rhs == &swap.1 { + if rhs == swap.0 || rhs == swap.1 { index_uids.push(rhs); } } } K::TaskCancelation { .. } | K::TaskDeletion { .. } | K::DumpExport { .. } | K::Snapshot => { - () } }; for index_uid in index_uids { - if index_uid == &swap.0 { + if index_uid == swap.0 { *index_uid = swap.1.to_owned(); - } else if index_uid == &swap.1 { + } else if index_uid == swap.1 { *index_uid = swap.0.to_owned(); } } diff --git a/meili-snap/src/lib.rs b/meili-snap/src/lib.rs index 020c4c5b4..e9f341e8b 100644 --- a/meili-snap/src/lib.rs +++ b/meili-snap/src/lib.rs @@ -6,7 +6,7 @@ use std::sync::Mutex; pub use insta; use once_cell::sync::Lazy; -static SNAPSHOT_NAMES: Lazy>> = Lazy::new(|| Mutex::default()); +static SNAPSHOT_NAMES: Lazy>> = Lazy::new(Mutex::default); /// Return the md5 hash of the given string pub fn hash_snapshot(snap: &str) -> String { @@ -25,7 +25,7 @@ pub fn default_snapshot_settings_for_test(name: Option<&str>) -> (insta::Setting let test_name = std::thread::current().name().unwrap().rsplit("::").next().unwrap().to_owned(); - let path = Path::new("snapshots").join(filename).join(&test_name).to_owned(); + let path = Path::new("snapshots").join(filename).join(&test_name); settings.set_snapshot_path(path.clone()); let snap_name = if let Some(name) = name { Cow::Borrowed(name) diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index e075428d5..2249cb9b7 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -87,21 +87,20 @@ pub fn create_app( .configure(|s| dashboard(s, enable_dashboard)); #[cfg(feature = "metrics")] let app = app.configure(|s| configure_metrics_route(s, opt.enable_metrics_route)); - let app = app - .wrap( - Cors::default() - .send_wildcard() - .allow_any_header() - .allow_any_origin() - .allow_any_method() - .max_age(86_400), // 24h - ) - .wrap(middleware::Logger::default()) - .wrap(middleware::Compress::default()) - .wrap(middleware::NormalizePath::new(middleware::TrailingSlash::Trim)); + #[cfg(feature = "metrics")] let app = app.wrap(Condition::new(opt.enable_metrics_route, route_metrics::RouteMetrics)); - app + app.wrap( + Cors::default() + .send_wildcard() + .allow_any_header() + .allow_any_origin() + .allow_any_method() + .max_age(86_400), // 24h + ) + .wrap(middleware::Logger::default()) + .wrap(middleware::Compress::default()) + .wrap(middleware::NormalizePath::new(middleware::TrailingSlash::Trim)) } // TODO: TAMO: Finish setting up things @@ -148,7 +147,7 @@ pub fn setup_meilisearch(opt: &Opt) -> anyhow::Result<(IndexScheduler, AuthContr Ok(()) => (index_scheduler, auth_controller), Err(e) => { std::fs::remove_dir_all(&opt.db_path)?; - return Err(e.into()); + return Err(e); } } } else if !empty_db && !opt.ignore_dump_if_db_exists { @@ -164,7 +163,7 @@ pub fn setup_meilisearch(opt: &Opt) -> anyhow::Result<(IndexScheduler, AuthContr Ok(()) => (index_scheduler, auth_controller), Err(e) => { std::fs::remove_dir_all(&opt.db_path)?; - return Err(e.into()); + return Err(e); } } } @@ -232,7 +231,7 @@ fn import_dump( keys.push(key); } - let indexer_config = index_scheduler.indexer_config().clone(); + let indexer_config = index_scheduler.indexer_config(); // /!\ The tasks must be imported AFTER importing the indexes or else the scheduler might // try to process tasks while we're trying to import the indexes. diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index 258265b72..0181d3511 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -147,7 +147,7 @@ Anonymous telemetry:\t\"Enabled\"" } if let Some(instance_uid) = analytics.instance_uid() { - eprintln!("Instance UID:\t\t\"{}\"", instance_uid.to_string()); + eprintln!("Instance UID:\t\t\"{}\"", instance_uid); } eprintln!(); diff --git a/meilisearch-http/src/routes/indexes/documents.rs b/meilisearch-http/src/routes/indexes/documents.rs index 16a777c9c..2aa805c46 100644 --- a/meilisearch-http/src/routes/indexes/documents.rs +++ b/meilisearch-http/src/routes/indexes/documents.rs @@ -262,7 +262,7 @@ async fn document_addition( Err(index_scheduler::Error::FileStore(file_store::Error::IoError(e))) if e.kind() == ErrorKind::NotFound => { - () + } Err(e) => { log::warn!("Unknown error happened while deleting a malformed update file with uuid {uuid}: {e}"); diff --git a/meilisearch-http/src/routes/indexes/settings.rs b/meilisearch-http/src/routes/indexes/settings.rs index 34612b52c..4e33cb0b4 100644 --- a/meilisearch-http/src/routes/indexes/settings.rs +++ b/meilisearch-http/src/routes/indexes/settings.rs @@ -45,7 +45,7 @@ macro_rules! make_setting_route { let index_uid = IndexUid::try_from(index_uid.into_inner())?.into_inner(); let task = KindWithContent::SettingsUpdate { index_uid, - new_settings, + new_settings: Box::new(new_settings), is_deletion: true, allow_index_creation, }; @@ -84,7 +84,7 @@ macro_rules! make_setting_route { let index_uid = IndexUid::try_from(index_uid.into_inner())?.into_inner(); let task = KindWithContent::SettingsUpdate { index_uid, - new_settings, + new_settings: Box::new(new_settings), is_deletion: false, allow_index_creation, }; @@ -443,7 +443,7 @@ pub async fn update_all( let index_uid = IndexUid::try_from(index_uid.into_inner())?.into_inner(); let task = KindWithContent::SettingsUpdate { index_uid, - new_settings, + new_settings: Box::new(new_settings), is_deletion: false, allow_index_creation, }; @@ -474,8 +474,8 @@ pub async fn delete_all( let allow_index_creation = index_scheduler.filters().allow_index_creation; let index_uid = IndexUid::try_from(index_uid.into_inner())?.into_inner(); let task = KindWithContent::SettingsUpdate { - index_uid: index_uid, - new_settings, + index_uid, + new_settings: Box::new(new_settings), is_deletion: true, allow_index_creation, }; diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index ba7f30c36..ca569f903 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -275,7 +275,7 @@ pub fn create_all_stats( limit: Some(1), ..Query::default() })?; - let processing_index = processing_task.first().and_then(|task| task.index_uid().clone()); + let processing_index = processing_task.first().and_then(|task| task.index_uid()); for (name, index) in index_scheduler.indexes()? { if !search_rules.is_index_authorized(&name) { continue; @@ -286,7 +286,7 @@ pub fn create_all_stats( let rtxn = index.read_txn()?; let stats = IndexStats { number_of_documents: index.number_of_documents(&rtxn)?, - is_indexing: processing_index.as_deref().map_or(false, |index_name| name == index_name), + is_indexing: processing_index.map_or(false, |index_name| name == index_name), field_distribution: index.field_distribution(&rtxn)?, }; diff --git a/meilisearch-http/src/routes/tasks.rs b/meilisearch-http/src/routes/tasks.rs index 775d04800..cc7c11341 100644 --- a/meilisearch-http/src/routes/tasks.rs +++ b/meilisearch-http/src/routes/tasks.rs @@ -113,14 +113,14 @@ pub struct DetailsView { pub dump_uid: Option, #[serde(skip_serializing_if = "Option::is_none")] #[serde(flatten)] - pub settings: Option>, + pub settings: Option>>, #[serde(skip_serializing_if = "Option::is_none")] pub indexes: Option>, } impl From
for DetailsView { fn from(details: Details) -> Self { - match details.clone() { + match details { Details::DocumentAdditionOrUpdate { received_documents, indexed_documents } => { DetailsView { received_documents: Some(received_documents), @@ -471,7 +471,7 @@ async fn get_task( filters.uid = Some(vec![task_id]); if let Some(task) = index_scheduler.get_tasks(filters)?.first() { - let task_view = TaskView::from_task(&task); + let task_view = TaskView::from_task(task); Ok(HttpResponse::Ok().json(task_view)) } else { Err(index_scheduler::Error::TaskNotFound(task_id).into()) @@ -494,7 +494,7 @@ fn filter_out_inaccessible_indexes_from_query( match indexes { Some(indexes) => { for name in indexes.iter() { - if search_rules.is_index_authorized(&name) { + if search_rules.is_index_authorized(name) { query = query.with_index(name.to_string()); } } @@ -543,7 +543,7 @@ pub(crate) mod date_deserializer { DeserializeDateOption::After => { let datetime = datetime .checked_add(Duration::days(1)) - .ok_or(serde::de::Error::custom("date overflow"))?; + .ok_or_else(|| serde::de::Error::custom("date overflow"))?; Ok(datetime) } } diff --git a/meilisearch-http/src/search.rs b/meilisearch-http/src/search.rs index a625b44e0..813f8a6c5 100644 --- a/meilisearch-http/src/search.rs +++ b/meilisearch-http/src/search.rs @@ -552,7 +552,7 @@ fn parse_filter(facets: &Value) -> Result, MeilisearchHttpError> Ok(condition) } Value::Array(arr) => parse_filter_array(arr), - v => Err(MeilisearchHttpError::InvalidExpression(&["Array"], v.clone()).into()), + v => Err(MeilisearchHttpError::InvalidExpression(&["Array"], v.clone())), } } @@ -570,8 +570,7 @@ fn parse_filter_array(arr: &[Value]) -> Result, MeilisearchHttpEr return Err(MeilisearchHttpError::InvalidExpression( &["String"], v.clone(), - ) - .into()) + )) } } } @@ -581,8 +580,7 @@ fn parse_filter_array(arr: &[Value]) -> Result, MeilisearchHttpEr return Err(MeilisearchHttpError::InvalidExpression( &["String", "[String]"], v.clone(), - ) - .into()) + )) } } } diff --git a/meilisearch-types/src/tasks.rs b/meilisearch-types/src/tasks.rs index 189014f66..4b6705655 100644 --- a/meilisearch-types/src/tasks.rs +++ b/meilisearch-types/src/tasks.rs @@ -102,7 +102,7 @@ pub enum KindWithContent { }, SettingsUpdate { index_uid: String, - new_settings: Settings, + new_settings: Box>, is_deletion: bool, allow_index_creation: bool, }, @@ -417,14 +417,13 @@ impl FromStr for Kind { } #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -#[allow(clippy::large_enum_variant)] pub enum Details { DocumentAdditionOrUpdate { received_documents: u64, indexed_documents: Option, }, SettingsUpdate { - settings: Settings, + settings: Box>, }, IndexInfo { primary_key: Option,