From ed29cceae940d580ccdf5407c7dea0c07d168d86 Mon Sep 17 00:00:00 2001 From: Gregory Conrad Date: Wed, 23 Nov 2022 22:33:06 -0500 Subject: [PATCH] perf: Prevent reindex in searchable set case when not needed --- milli/src/update/settings.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 586198c52..aed2d951e 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -349,6 +349,16 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> { fn update_searchable(&mut self) -> Result { match self.searchable_fields { Setting::Set(ref fields) => { + let did_change = self + .index + .searchable_fields(self.wtxn)? + .map(|f| f.into_iter().map(String::from).collect::>()) + .map(|old_fields| fields != &old_fields) + .unwrap_or(true); // if old_fields was None before, it was changed + if !did_change { + return Ok(false); + } + // every time the searchable attributes are updated, we need to update the // ids for any settings that uses the facets. (distinct_fields, filterable_fields). let old_fields_ids_map = self.index.fields_ids_map(self.wtxn)?; @@ -376,7 +386,7 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> { Ok(true) } Setting::Reset => Ok(self.index.delete_all_searchable_fields(self.wtxn)?), - Setting::NotSet => return Ok(false), + Setting::NotSet => Ok(false), } }