Skip to content

Commit

Permalink
Set return fields in contact lookup for performance boost
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Feb 7, 2017
1 parent 3803954 commit 146aef0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions includes/contact_component.inc
Original file line number Diff line number Diff line change
Expand Up @@ -575,17 +575,17 @@ function wf_crm_contact_search($node, $component, $params, $str = NULL) {
}
$limit = $str ? 12 : 500;
$ret = array();
$display = $component['extra']['results_display'];
$display_fields = array_values($component['extra']['results_display']);
$search_field = 'display_name';
$sort_field = 'sort_name';
// Search and sort based on the selected display field
if (!in_array('display_name', $display)) {
$display_options = array_values($display);
$search_field = $sort_field = $display_options[0];
if (!in_array('display_name', $display_fields)) {
$search_field = $sort_field = $display_fields[0];
}
$params += array(
'rowCount' => $limit,
'sort' => $sort_field,
'return' => $display_fields,
);
if ($str) {
$str = str_replace(' ', '%', CRM_Utils_Type::escape($str, 'String'));
Expand All @@ -602,7 +602,7 @@ function wf_crm_contact_search($node, $component, $params, $str = NULL) {
// Autocomplete results
if ($str) {
foreach (wf_crm_aval($result, 'values', array()) as $contact) {
if ($name = wf_crm_format_contact($contact, $display)) {
if ($name = wf_crm_format_contact($contact, $display_fields)) {
$ret[] = array('id' => $contact['id'], 'name' => $name);
}
}
Expand All @@ -618,7 +618,7 @@ function wf_crm_contact_search($node, $component, $params, $str = NULL) {
}
foreach (wf_crm_aval($result, 'values', array()) as $contact) {
// Select lists will be escaped by FAPI
if ($name = wf_crm_format_contact($contact, $display, FALSE)) {
if ($name = wf_crm_format_contact($contact, $display_fields, FALSE)) {
$ret[$contact['id']] = $name;
}
}
Expand Down

0 comments on commit 146aef0

Please sign in to comment.