Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards CRM-19815, CRM-19830 make pseudoconstant handling more generic in order to improve performance #9885

Merged
merged 1 commit into from
Feb 24, 2017

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Feb 23, 2017

The point of this change is to open up option-value-based pseudoconstant handling from hard-coded fields to metadata based fields. Using pseudoconstants rather than hard-coding joins to the option value table removes slow joins and improves speed. In some cases I have been able to get 60 fold increases.

@seamuslee001 I am working through #9631 to feel extra sure about the components. I have done the following checks here.

I've added a bunch of api tests and done some search tests by trying the contact table option_value fields from search builder, advanced search & export. Profile search listings I tested too, the enotice pre-exists :-)


@eileenmcnaughton
Copy link
Contributor Author

eileenmcnaughton commented Feb 23, 2017

I also grepped where CRM_Contact_BAO_Query::apiQuery is called from & the only place I could see where returnProperties might include prefix_id was tokens. I tested & found they used individual_prefix which is supported by virtue of being the machine name of the prefix_id option group. Also email greeting options etc look like

Dear {contact.individual_prefix} {contact.first_name} {contact.last_name}

@@ -5829,12 +5811,40 @@ public function convertToPseudoNames(&$dao, $return = FALSE, $usedForAPI = FALSE
$val = $dao->{$value['idCol']};
if ($key == 'groups') {
$dao->groups = $this->convertGroupIDStringToLabelString($dao, $val);
return;
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton That will be problematic in PHP7 PHPCompatibility/PHPCompatibility#292

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at the very leaset maybe a false positive not sure i see it come up in phpcs on php7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, it's within a foreach loop - that seems to say 'outside a foreach loop'

foreach ($this->_pseudoConstantsSelect as $key => $value) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True didn't notice the foreach but have checked and seems ok but just something to watch out

Copy link
Contributor

@seamuslee001 seamuslee001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this and it looks good and export looks good. Once test is sorted then should be all good

@seamuslee001
Copy link
Contributor

@eileenmcnaughton fixed the test for you, looks to be just whitespace change in the AS part of the sql

Using metadata pseudoconstants we can remove joins on the option_value table, which hur performance. This patch
only opens it up within the context of the Contact table. It is intended to open the code up to
allow us to extend the performance advantage of dropping the bad join to other entities.

The following fields have metadata links to the
option_value table:
 gender_id
 prefix_id
 suffix_id
 preferred_communication_method
 communication_style_id
 preferred_language

The general pattern for the api is to return (eg) communication_style_id = 1, communication_style = 'Formal', where communication_style is the db name of the option group for communication_style_id.

preferred_communication_method is the exception. For api calls it returns an array of ids like all other api calls.
However, it returns a string of names for non-api calls on that field, allowing us to avoid handling it in a number of other places.

I added tests to ensure no change on the api inputs & outputs and searched these fields through search builder & advanced
search + export. I also checked profile search listings. They are not using the convert routine & have some e-notices that
pre-existed, but no regression I could see.
@eileenmcnaughton eileenmcnaughton merged commit bf3a316 into civicrm:master Feb 24, 2017
@eileenmcnaughton eileenmcnaughton deleted the search branch February 24, 2017 02:49
@eileenmcnaughton eileenmcnaughton changed the title CRM-19815, CRM-19830 make pseudoconstant handling more generic in order to improve performance Towards CRM-19815, CRM-19830 make pseudoconstant handling more generic in order to improve performance Feb 24, 2017
monishdeb pushed a commit to monishdeb/civicrm-core that referenced this pull request May 2, 2017
CRM-19815, CRM-19830 make pseudoconstant handling more generic in order to improve performance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants