Introduce an optimization when the searchable attributes are ordered

This commit is contained in:
Clément Renault 2020-11-03 19:59:09 +01:00
parent 01c4f5abcd
commit a31db33e93
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -69,6 +69,21 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
let result = match value {
Some(fields_names) => {
let mut fields_ids_map = current_fields_ids_map.clone();
let searchable_fields: Vec<_> =
fields_names.iter()
.map(|name| fields_ids_map.insert(name))
.collect::<Option<Vec<_>>>()
.context("field id limit reached")?;
// If the searchable fields are ordered we don't have to generate a new `FieldsIdsMap`.
if searchable_fields.windows(2).all(|win| win[0] < win[1]) {
(
fields_ids_map,
Some(searchable_fields),
current_displayed_fields.map(ToOwned::to_owned),
)
} else {
// We create or generate the fields ids corresponding to those names.
let mut fields_ids_map = FieldsIdsMap::new();
let mut searchable_fields = Vec::new();
@ -97,6 +112,7 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
};
(fields_ids_map, Some(searchable_fields), displayed_fields)
}
},
None => (
current_fields_ids_map.clone(),