Details
-
Type: Improvement
-
Status: Won't Do
-
Priority: Minor
-
Resolution: Won't Do
-
Affects Version/s: 4.6, 4.7
-
Fix Version/s: Unscheduled
-
Component/s: Core CiviCRM
-
Labels:
-
Versioning Impact:Patch (backwards-compatible bug fixes)
-
Documentation Required?:Developer Doc
-
Epic Link:
-
Funding Source:Needs Funding
Description
I always wondered why we have the group_contact_cache table ... we could very well cache the smart group results in the group_contact table (with status = 'Smart') ... this way any queries on groups would just look at one table rather than have these Russian doll joins and ors!
To list all contacts in a smart group:
SELECT contact_id FROM civicrm_group_contact WHERE group_id = xxx AND status IN ('Added', 'Smart');
Then, to refresh the smart group:
DELETE FROM civicrm_group_contact WHERE group_id = xxx AND status = 'Smart'; INSERT IGNORE INTO civicrm_group_contact ... (results from smart group query)
The INSERT IGNORE with a primary key on (group_id, contact_id) would take care of not adding smart group query results that already have an 'Added' or 'Removed' status.