From 2db738dbac9b3e35b69a989b835e27b58f44d5a1 Mon Sep 17 00:00:00 2001 From: Gregory Conrad Date: Sat, 26 Nov 2022 13:26:39 -0500 Subject: [PATCH] refactor: rewrite method chain to be more readable --- milli/src/update/settings.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index aed2d951e..7d281262a 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -349,12 +349,17 @@ 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 + // Check to see if the searchable fields changed before doing anything else + let old_fields = self.index.searchable_fields(self.wtxn)?; + let did_change = match old_fields { + // If old_fields is Some, let's check to see if the fields actually changed + Some(old_fields) => { + let new_fields = fields.iter().map(String::as_str).collect::>(); + new_fields != old_fields + } + // If old_fields is None, the fields have changed (because they are being set) + None => true, + }; if !did_change { return Ok(false); }