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

CRM-21110 Get Total relationships without need for extra table #11009

Merged
merged 1 commit into from
Sep 30, 2017

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Sep 21, 2017

Overview

This improves on the patch for CRM-21110 from #10907 by keeping the total_relationships array key but getting that value without the need for a separate table

@eileenmcnaughton @monishdeb I have deployed this version of the patch to AUG prod at the moment and @ineffyble does report that the relationships tab feels snappier and i think this is better because it means no temporary table


@seamuslee001
Copy link
Contributor Author

Jenkins test this please

@colemanw
Copy link
Member

Code looks good to me, but I haven't grokked that query so I'm just going on looks. @eileenmcnaughton @monishdeb any comments?

Copy link
Contributor

@twomice twomice left a comment

Choose a reason for hiding this comment

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

In general, I see no problem here, and agree that all else being equal it's preferable to avoid temp tables. (BTW, if we have to use temp tables, it would be good to name them something that looks obviously temporary, like 'TEMP_civicrm_contact_relationships', since 'civicrm_contact_relationships' looks like it could be a real table and thus be confusing to new devs examining the code.)

My brief testing (with a contact having 6K relationships, and a contact having just 1 relationship), shows no measurable difference in performance on the Relationships tab, comparing with vs. without this PR.

I believe this PR does no harm in performance and improves the code. I recommend merging (after the minor capitalization fix mentioned in my comment).

return $relationshipCount;
}
else {

if ($includeTotalCount) {
$values['total_relationships'] = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_contact_relationships");
$values['total_relationships'] = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM ({$queryString}) as r");
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor point, but capitalize SQL keyword AS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @twomice

@twomice
Copy link
Contributor

twomice commented Sep 29, 2017

To be more specific:

  • I performed a visual comparison of loading the Relationships tab for a contact having 6K relationships, and a contact having just 1 relationship, comparing load time with vs. without this PR. I found no measurable difference in performance on the Relationships tab.
  • I examined the relevant SQL query, and noted that it's using only index-based inner joins; this makes the query itself fairly quick, and it makes sense that re-running it a second time is no more resource intensive than creating the temp table.

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton @monishdeb i think this should be mergable now following @twomice's review

@monishdeb
Copy link
Member

Yup it make sense. Merging based on @twomice feedback and my code review.

@monishdeb monishdeb merged commit 31f0574 into civicrm:master Sep 30, 2017
@monishdeb monishdeb deleted the CRM-21110-2 branch September 30, 2017 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants