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

Allow other base tables for api4-based smart groups #17003

Closed
wants to merge 1 commit into from

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Apr 7, 2020

Overview

Expands support for API based smart groups, allowing any api entity as the starting point, not just Contact.

Before

Could only create a smart group from Contact API entity.

After

Any API entity allowed. The API explorer supports this, and also now provides some rudimentary validation to ensure contact_id is selected by the API query.

Technical Details

The GroupContactCache was tacking on an additional WHERE clause to exclude removed group contacts. I converted it to a HAVING clause for API queries because that's more flexible.

@civibot
Copy link

civibot bot commented Apr 7, 2020

(Standard links)

@civibot civibot bot added the master label Apr 7, 2020
if (CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) {$contactQuery['from']}") > 0) {
CRM_Core_DAO::executeQuery("INSERT IGNORE INTO $tempTable (group_id, contact_id) {$contactQuery['select']} {$contactQuery['from']}");
}
CRM_Core_DAO::executeQuery("INSERT IGNORE INTO $tempTable (group_id, contact_id) {$contactQuery['select']} {$contactQuery['from']}");
Copy link
Member Author

@colemanw colemanw Apr 7, 2020

Choose a reason for hiding this comment

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

I removed the SELECT COUNT for 2 reasons:

  1. It was causing the API query to crash because swapping the SELECT clause for SELECT COUNT(*) loses our field alias which the HAVING clause relies on.
  2. I'm unclear about the effectiveness of this optimization. It looks to me like it's causing the query to run twice, so I'm not sure how that's more efficient. Looks like fairly recent work of @seamuslee001 though so I'll let him chime in here and tell me why I'm wrong :)

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like this actually came from @mattwire in #15588.
Any thoughts Matthew?

Copy link
Contributor

Choose a reason for hiding this comment

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

@colemanw Can you pull this bit out into a separate PR? It was part of the refactoring to improve performance / reduce database deadlocks work so changing it carries quite a high risk (ie. needs testing thoroughly). That said, the refactoring was an improvement rather than an end-point so I'm happy to see further improvements like this :-)
For example, in theory we should not have needed the INSERT IGNORE - INSERT should have been ok, but in practise it wasn't.. (probably because further improvement is required to reduce concurrency).

Copy link
Member Author

Choose a reason for hiding this comment

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

@mattwire sure - see #17011

@colemanw
Copy link
Member Author

colemanw commented Apr 9, 2020

retest this please

@colemanw colemanw force-pushed the smartererGroups branch 2 times, most recently from 9f74998 to 6e4e89d Compare April 10, 2020 02:19
@colemanw
Copy link
Member Author

The "additional cleanup" commit was causing tests to crash so I'm splitting that off to a separate PR to investigate. This PR should be merge-ready now.

@colemanw
Copy link
Member Author

retest this please

@colemanw colemanw closed this Apr 16, 2020
@colemanw colemanw deleted the smartererGroups branch April 16, 2020 12:06
colemanw added a commit to colemanw/civicrm-core that referenced this pull request Apr 16, 2020
Allow other base tables for api4-based smart groups
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.

2 participants