From 01144b2c742d46370ef09c92be5334d44b78aec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 8 Jul 2024 16:46:53 +0200 Subject: [PATCH] Make the edit documents by function route experimental --- index-scheduler/src/features.rs | 13 +++++++++++++ meilisearch-types/src/features.rs | 1 + meilisearch/src/routes/features.rs | 15 +++++++++++++-- meilisearch/src/routes/indexes/documents.rs | 5 +++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/index-scheduler/src/features.rs b/index-scheduler/src/features.rs index ae8e6728a..fbb273e54 100644 --- a/index-scheduler/src/features.rs +++ b/index-scheduler/src/features.rs @@ -68,6 +68,19 @@ impl RoFeatures { .into()) } } + + pub fn check_edit_documents_by_function(&self, disabled_action: &'static str) -> Result<()> { + if self.runtime.edit_documents_by_function { + Ok(()) + } else { + Err(FeatureNotEnabledError { + disabled_action, + feature: "edit documents by function", + issue_link: "https://github.com/orgs/meilisearch/discussions/762", + } + .into()) + } + } } impl FeatureData { diff --git a/meilisearch-types/src/features.rs b/meilisearch-types/src/features.rs index dda9dee51..f15a1c999 100644 --- a/meilisearch-types/src/features.rs +++ b/meilisearch-types/src/features.rs @@ -6,6 +6,7 @@ pub struct RuntimeTogglableFeatures { pub vector_store: bool, pub metrics: bool, pub logs_route: bool, + pub edit_documents_by_function: bool, } #[derive(Default, Debug, Clone, Copy)] diff --git a/meilisearch/src/routes/features.rs b/meilisearch/src/routes/features.rs index 0e02309fa..14aece10f 100644 --- a/meilisearch/src/routes/features.rs +++ b/meilisearch/src/routes/features.rs @@ -47,6 +47,8 @@ pub struct RuntimeTogglableFeatures { pub metrics: Option, #[deserr(default)] pub logs_route: Option, + #[deserr(default)] + pub edit_documents_by_function: Option, } async fn patch_features( @@ -66,13 +68,21 @@ async fn patch_features( vector_store: new_features.0.vector_store.unwrap_or(old_features.vector_store), metrics: new_features.0.metrics.unwrap_or(old_features.metrics), logs_route: new_features.0.logs_route.unwrap_or(old_features.logs_route), + edit_documents_by_function: new_features + .0 + .edit_documents_by_function + .unwrap_or(old_features.edit_documents_by_function), }; // explicitly destructure for analytics rather than using the `Serialize` implementation, because // the it renames to camelCase, which we don't want for analytics. // **Do not** ignore fields with `..` or `_` here, because we want to add them in the future. - let meilisearch_types::features::RuntimeTogglableFeatures { vector_store, metrics, logs_route } = - new_features; + let meilisearch_types::features::RuntimeTogglableFeatures { + vector_store, + metrics, + logs_route, + edit_documents_by_function, + } = new_features; analytics.publish( "Experimental features Updated".to_string(), @@ -80,6 +90,7 @@ async fn patch_features( "vector_store": vector_store, "metrics": metrics, "logs_route": logs_route, + "edit_documents_by_function": edit_documents_by_function, }), Some(&req), ); diff --git a/meilisearch/src/routes/indexes/documents.rs b/meilisearch/src/routes/indexes/documents.rs index 3b1dcba22..9faf8bc67 100644 --- a/meilisearch/src/routes/indexes/documents.rs +++ b/meilisearch/src/routes/indexes/documents.rs @@ -595,6 +595,11 @@ pub async fn edit_documents_by_function( analytics: web::Data, ) -> Result { debug!(parameters = ?params, "Edit documents by function"); + + index_scheduler + .features() + .check_edit_documents_by_function("Using the documents edit route")?; + let index_uid = IndexUid::try_from(index_uid.into_inner())?; let index_uid = index_uid.into_inner(); let params = params.into_inner();