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-20594: Optimize Counting of Reltionships on Contact Summary #10371

Conversation

MiyaNoctem
Copy link
Contributor

@MiyaNoctem MiyaNoctem commented May 17, 2017

Contacts with a lot of relationships (over 5000) were taking a lot of time to load. This was because the count of relationships was being done by fetching ALL records of relationships associated to the contact, and then counting the number of elements in the resulting array.

Fixed by changing the call to CRM_Contact_BAO_Relationship::getRelationship() being used in CRM_Contact_BAO_Contact::getCountComponent(), passing the $count parameter as 1 instead of 0, so counting is done by the database by building a 'SELECT COUNT(*)' type of query.

Also, removed some unnecessary joins when counting records in DB, by embedding them in an if statement, entered when $count flag is different to 1.


Contacts with a lot of relationships (over 5000) were taking a lot of time to
load.  This was because the count of relationships was being done by fetching
ALL records of relationships associated to the contact, and then counting the
number of elements in the resulting array.

Fixed by changing the call to CRM_Contact_BAO_Relationship::getRelationship()
being used in CRM_Contact_BAO_Contact::getCountComponent(), passing the
$count parameter as 1 instead of 0, so counting is done by the database by
building a 'SELECT COUNT(*)' type of query.

Also, removed some unnecessary joins when counting records in DB, ie. when
$count flag is 1.
@MiyaNoctem MiyaNoctem changed the title CRM-20594: Optimze Counting of Reltionships on Contact Summary CRM-20594: Optimize Counting of Reltionships on Contact Summary May 17, 2017
Copy link
Member

@colemanw colemanw left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks for the PR.

@seamuslee001
Copy link
Contributor

Jenkins re test this please

2 similar comments
@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

Jenkins re test this please

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.

5 participants