-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
dev/core#192 - Search builder fails for != smart group filter #12344
Conversation
(Standard links)
|
efadb31
to
06bd476
Compare
@jitendrapurohit I encountered an issue, with this patch. Let's say Contact A and B is in regular group RG AND contact B and C is smart group SG. Then when I do a search with 'Group != SG' then it returns all the 4 contacts. Shouldn't we expect only Contact A in the result list? On debugging I found that at this query it excludes the smart group ID and eventually didn't build any where clause for the chosen smart group. But the intent of this patch is to make = and != operator works like IN/NOT IN respectively for smart group, but the use-case described above bothers me to as it still includes the contact in the result list, which is in SG |
Thanks @monishdeb, there seems to be multiple issues related to smart and regular group search. Not sure, but they seem to stem from work done on #9506 and #8645. Listing some of the issues that I encountered while fixing the above comment -
I've updated the PR with the fixes for the above use-cases. |
Considering A, B, C and D are 4 contacts, where Contact A and B is in regular group RG AND contact B and C is smart group SG, C and D are in second SG2. Here's my test cases after applying the patches:
Here we should exclude the OR operator which is expensive in terms of performance and both the sub-clause is same. @jitendrapurohit so overall :
|
2b231e0
to
60185cd
Compare
Updated the PR and handled the NOT operator clauses in the same way as we do for |
@jitendrapurohit it seems that the 1 test failure is related to this patch. Can you fix that? |
60185cd
to
db016c4
Compare
weird, the failing test is the one added in this PR and it works fine on my local. Anyway, I've pushed a commit which should fix the same on jenkin too 👍 |
test this please |
(re-running tests as 22 days ago) |
@monishdeb looks like this needs a final ok from you |
@eileenmcnaughton I am not sure in this case, as for smart group, it adds a subquery when != or NOT IN operator is used, which will cause a performance issue. As per the patch when I do a search on criteria
The use of OR operator and subquery will cause a performance hit on large site. As I recall, I had a discussion with you earlier to have separate LEFT JOINS for smart and regular groups respectively and in this way we can resolved the performance issue for groups. So should we implement this change in core under this issue? |
Hmm - yeah - we should get some performance testing for sure! @seamuslee001 has a good site for testing group search performance on |
I've tried this out on a client site which we had found the accuracy problem while testing a 4.6 -> 5.6 upgrade. Upgraded to 5.7 now and applied this patch, and it actually get's the right results and doesn't WSOD. Not exactly sure out this site compares to Seamus's site...but we got not quite 100K contacts, several hundred smart groups, smart groups based on activities, with millions of activities....and logging enabled...At the very least, this is better than it was with 5.6 and no patch! |
@jackrabbithanna we have somewhere about 700K maybe of contacts about 1K of groups (we are nuts) but that being said @eileenmcnaughton i would recommend merging based on @jackrabbithanna 's testing |
@seamuslee001 Any chance you can give it a quick spin to double check? Looking at the query I think the OR might not be the problem OR that gave all those WSODs in 4.6 - in that it is in the WHERE not the join and it's 2 fields on the same table. |
I was testing with 4 criteria, using 3 there where contact = group, and one where contact != group.. All groups were smart groups. It was a little slow, takes about 220s to return the search results....so by better than not working, yeah, but pretty slow...I'll take really slow over nothing at all any day though. All the groups use criteria looking for if a contact has an activity of a certain type, between certain activity_date_times , with certain activity status... MySQL 5.5 / PHP 5.6 instance, plenty of memory, no memcache, no varnish, no redis... |
OK - I've added merge-ready - I'd LIKE @seamuslee001 to give it a spin BUT if I look at these criteria
Then I think there is a good case to merge. I'll just recheck string escaping now |
actually let's just check that escaping some more - I think it could be 'better' |
db016c4
to
44ea65e
Compare
@jitendrapurohit the test works :-) |
Jenkins test this please |
44ea65e
to
8ac94e7
Compare
jenkins, retest this please |
CRM/Contact/BAO/Query.php
Outdated
$groupClause[] = " ( " . $this->addGroupContactCache($smartGroupIDs, NULL, "contact_a", $op) . " ) "; | ||
$groupContactCacheClause = ''; | ||
if (count($smartGroupIDs) || empty($value)) { | ||
$isNullOp = (strpos($op, 'NULL') !== FALSE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not just doing
($op == 'IS NULL')
- we don't support people playing fast & loose with the $op var do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see this variable is not required in this function after the latest changes. Pushed the commit to remove this line completely. Thanks for identifying.
8ac94e7
to
5260680
Compare
CRM/Contact/BAO/Query.php
Outdated
if (!empty($groupContactCacheClause)) { | ||
if ($isNotOp) { | ||
$groupIds = implode(',', (array) $smartGroupIDs); | ||
$gcTable = "`civicrm_group_contact-{$groupIds}`"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jitendrapurohit don't we still have appended input here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still some places in civi where id is appended to the group table and was little sceptic about removing it here. But it looks like they are not dependent on changes made in this file so i've just removed it now. will wait for the test build to run clean this time too.
5260680
to
e1ba0be
Compare
test this please |
e1ba0be
to
a9af144
Compare
With the last change in removing id from
i.e, searching for contact with group title should retrieve all the group for the contacts which was done with the additional alias added to the query. The latest update to this PR adds uniqid to the table name in the from clause which fixes it and retrieves correct number of groups in the result. |
a9af144
to
a9e20b9
Compare
jenkins, retest this please |
a9e20b9
to
f30aa75
Compare
woot tests are passing !! @jackrabbithanna do you want to give this a last spin & then we can merge if all good |
Sorry, I just noticed you pinged me on this.....I'll test this over the weekend and let you know.... |
Tried this out on one of our dev servers of a site that uses groups heavily, seems accurate, and faster....we'll be testing this more as the client and us use it. |
@jackrabbithanna thanks - I'm going to merge this now since it has been tested by you more than once now & also has unit tests. It will be another 6 weeks before it goes out live - during which time you'll be testing further - so please let us know any more updates from your testing |
We seem to be checking if the cache needs a rebuild and IF SO doing 2 actions 1) rebuilding it 2) permitting access to contacts related to it When really it should do only 1) above - this patch changes as such This seems to be whackamole off civicrm#12344 going too far one way & civicrm#13448 fixing but adding this new variant
We seem to be checking if the cache needs a rebuild and IF SO doing 2 actions 1) rebuilding it 2) permitting access to contacts related to it When really it should do only 1) above - this patch changes as such This seems to be whackamole off civicrm#12344 going too far one way & civicrm#13448 fixing but adding this new variant
We seem to be checking if the cache needs a rebuild and IF SO doing 2 actions 1) rebuilding it 2) permitting access to contacts related to it When really it should do only 1) above - this patch changes as such This seems to be whackamole off civicrm#12344 going too far one way & civicrm#13448 fixing but adding this new variant
This turned out tricksy - we also got #13662 - the underlying issue is poor test coverage of a fairly tricky bit of functionality. This change DID improve that & @seamuslee001 has promised to add follow up tests but hoping you can check the new PR @jitendrapurohit |
Overview
Fix smart group in search builder with
!=
operator.Before
Smart Group search on
Search Builder
result incorrect rows with!=
operatorAfter
Correct results are displayed.
Comments
Added unit test.
Gitlab - https://lab.civicrm.org/dev/core/issues/192