perf: limit reindex to when exact_attributes changes

This commit is contained in:
Gregory Conrad 2022-11-23 15:50:53 -05:00
parent 57c9f03e51
commit d19c8672bb
2 changed files with 18 additions and 10 deletions

View file

@ -465,14 +465,23 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
fn update_exact_attributes(&mut self) -> Result<bool> {
match self.exact_attributes {
Setting::Set(ref attrs) => {
let attrs = attrs.iter().map(String::as_str).collect::<Vec<_>>();
self.index.put_exact_attributes(self.wtxn, &attrs)?;
Ok(true)
}
Setting::Reset => {
self.index.delete_exact_attributes(self.wtxn)?;
Ok(true)
let old_attrs = self
.index
.exact_attributes(self.wtxn)?
.iter()
.cloned()
.map(String::from)
.collect::<HashSet<String>>();
if attrs != &old_attrs {
let attrs = attrs.iter().map(String::as_str).collect::<Vec<_>>();
self.index.put_exact_attributes(self.wtxn, &attrs)?;
Ok(true)
} else {
Ok(false)
}
}
Setting::Reset => Ok(self.index.delete_exact_attributes(self.wtxn)?),
Setting::NotSet => Ok(false),
}
}