refactor: Move clean_query up the stack.

This change is easy--we only had one caller.

This change means any query going against a
target with multiple `match_attrs`, such as
user names (first name, last) only has to
clean the query once per person.
This commit is contained in:
Steve Howell 2019-12-23 17:20:36 +00:00 committed by Tim Abbott
parent 5b01efda7b
commit 8448832bfe
1 changed files with 2 additions and 2 deletions

View File

@ -61,8 +61,6 @@ function clean_query(query) {
function query_matches_string(query, source_str, split_char) { function query_matches_string(query, source_str, split_char) {
source_str = people.remove_diacritics(source_str); source_str = people.remove_diacritics(source_str);
query = clean_query(query);
// If query doesn't contain a separator, we just want an exact // If query doesn't contain a separator, we just want an exact
// match where query is a substring of one of the target characters. // match where query is a substring of one of the target characters.
if (query.indexOf(split_char) > 0) { if (query.indexOf(split_char) > 0) {
@ -101,6 +99,8 @@ function query_matches_string(query, source_str, split_char) {
// account, there might be 2 attrs: their full name and their email. // account, there might be 2 attrs: their full name and their email.
// * split_char is the separator for this syntax (e.g. ' '). // * split_char is the separator for this syntax (e.g. ' ').
function query_matches_source_attrs(query, source, match_attrs, split_char) { function query_matches_source_attrs(query, source, match_attrs, split_char) {
query = clean_query(query);
return _.any(match_attrs, function (attr) { return _.any(match_attrs, function (attr) {
const source_str = source[attr].toLowerCase(); const source_str = source[attr].toLowerCase();
return query_matches_string(query, source_str, split_char); return query_matches_string(query, source_str, split_char);