Answers.Body: <p>Some clarification about 'getting smart groups to refresh'</p>
  
  <p>I assume you are using the button 'update smartgroup counts' from the Manage groups screen. This could perhaps be better called 'calculate missing smartgroup counts' (although that wouldn't fit on the button.....) - that button causes the count to be calculated for all groups that the cache has not been built for.</p>
  
  <p>Groups are only recalculated if they have aged out - by default the smart group timeout is 5 minutes. Pretty much whenever you save a contact it attempts to delete the cache for any smart groups that are more than those 5 minutes old (you can set the cache to less than 5 minutes or 0 for more caching). It will then re-fill the cache for that group next time you access it.</p>
  
  <p>If you barely ever edit contacts I guess the cache might not get cleared as often as it 'should' - you can schedule a job (Job.group_cache_flush) to run however often you want - if you do this it makes sense to set the setting 'smart_group_cache_refresh_mode' to 'deterministic' to stop it from also clearing on contact edit (note that this is often good to do for performance reasons)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-04T21:41:44.683Z
Answers.LastActivityDate: 2019-02-04T21:41:44.683Z
Answers.UserDisplayName: user4278
Answers.Body: <p>This answer was a comment by Joanne which I think deserved to be an answer</p>
  
  <blockquote>
    <p>I have tested this on 4.7.12 and found that Rebuild Smart Group Cache might not remove the contact whose criteria no longer comply with the smart group but Administer > System Settings > Cleanup Caches and Update Paths > Cleanup Caches does. So it seems to be a cache issue rather than a problem with the underlying smart group functionality</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-27T11:47:26.173Z
Answers.Text: I have the same problem (tested on 5.8.2 and 5.9.1) : when I select Individuals via Advanced Search, I get 19 results, while, when I modify an existing Smart Group towards the same criteria, I get only 9 in the Search, thus in the modified Smart Group. This is really bothering, because I have embedded smart Groups.
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-27T11:58:32.947Z
Answers.Text: I don't think it is just a cache issue : the problem occurs at the Search phase (before updating the Smart Group)
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-02T00:48:35.627Z
Answers.LastActivityDate: 2017-07-02T00:48:35.627Z
Answers.UserDisplayName: petednz - fuzion
Answers.Body: <p>I think you have a participant/event item in there - so that means some of your Contacts would have participated in more than one event!</p>
  
  <p>Try:
  Search Builder - it only returns the Contacts (unique)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-07T03:19:45.730Z
Answers.Text: I have rebuilt the filter using Search Builder and correctly obtain a dataset of 31 contacts. I have created a Smart Group from this dataset. If I now add a contact with the criteria to satisfy the smart group and view the smart group, the new contact appears in the smart group. However if I now change the criteria on the newly created contact so that it does not comply with the smart group it remains in the smart group. If I run the job Rebuild Smart Group Cache the smart group continues to contain the contact whose criteria no longer comply with the smart group.
Answers.UserDisplayName: Martin Fuggle
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-14T21:27:32.877Z
Answers.Text: I'm having a similar issue. Are you found some solution?
Answers.UserDisplayName: Francesc Bassas i Bullich
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-18T02:54:25.343Z
Answers.Text: I can reproduce similar problems whereby a smartgroup that is based on a date range is not refreshed when another contact should meet the date criteria
Answers.UserDisplayName: Dave T
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-28T00:54:20.130Z
Answers.Text: @MartinFuggle I have tested this on 4.7.12  and found that Rebuild Smart Group Cache might not remove the contact whose criteria no longer comply with the smart group but Administer > System Settings > Cleanup Caches and Update Paths > Cleanup Caches does. So it seems to be a cache issue rather than a problem with than the underlying smart group functionalility.
Answers.UserDisplayName: JoAnne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-02T19:34:10.200Z
Answers.Text: That last comment deserves to be an answer imo
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-27T14:19:27.657Z
Answers.Text: Moreover, if I remove all the search criteria from my Smart Group, I get only 15 Contacts in the search (against 1787 in my Data Base)
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-06T13:32:18.927Z
Answers.LastActivityDate: 2016-07-06T13:32:18.927Z
Answers.UserDisplayName: KarinG - Semper IT
Answers.Body: <p>I think there is a bug : I could reproduce it on the demo site :</p>
  
  <ul>
  <li>Create a group : TEST </li>
  <li>Advance search Individuals whose name contains
  "Adam" > You get 12 instances > Create smart group G1 under TEST</li>
  <li>Advance search Individuals whose name contains "ck" > You get 8
  instances > Create smart group G2 under TEST </li>
  <li>Advance search
  Individuals whose name contains "y" > You get 52 instances > Create
  smart group G3 under TEST </li>
  <li>Advance search Groups G1, G2, G3 > You get
  70 (you could expect 72, but there are some common results) > Create
  smart group "Total" under TEST</li>
  </ul>
  
  <p>Now, </p>
  
  <ul>
  <li>open G1 and modify search criteria : "Ad" instead of "Adam" > you get 18 instances (instead of 12), thus 6 more > Update the smart group</li>
  <li>Open group "Total" > you get 77 instead of 70, thus 7 more : why 7 and not 6 ?</li>
  </ul>
  
  <p>Now again, </p>
  
  <ul>
  <li>open G1 again and modify search criteria : "d" instead of "Ad" > You get 71 instances (instead of 18, thus a lot more) > Update the smart Group</li>
  <li>Open group "Total" > you still get 77 (while it should contain much more than that)</li>
  <li>Open "test" > you get 104 while there is no reason why it should be different from "Total" result</li>
  </ul>
  
  <p>I have just openned an issue : <a href="https://lab.civicrm.org/dev/core/issues/694" rel="nofollow noreferrer">https://lab.civicrm.org/dev/core/issues/694</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-04T09:27:21.003Z
Answers.LastActivityDate: 2019-02-04T18:29:00.573Z
Answers.LastEditDate: 2019-02-04T18:29:00.573Z
Answers.UserDisplayName: Jacques-Marie Moranne
Body: <p>I have read as much as I can about smart groups but I am having problems that I am not able to solve. I have a smart group which shows the same SQL as an Advanced Search but they produce different results.</p>
  
  <p><a href="https://i.sstatic.net/7lTEE.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7lTEE.jpg" alt="The Smart Group displays the criteria and the number of items selected being 25"></a></p>
  
  <p><a href="https://i.sstatic.net/1gztz.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1gztz.jpg" alt="The same query using a separate Advanced Search displays 31 items"></a></p>
  
  <p>If I refresh the smart group cache I get the same result.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-17T10:00:57.093Z
Comments.Text: Perhaps it maybe related with this [There is some inconsistent/confusing workflow managing contacts from smart groups?](http://civicrm.stackexchange.com/questions/15416/there-is-some-inconsistent-confusing-workflow-managing-contacts-from-smart-group)
Comments.UserDisplayName: Francesc Bassas i Bullich
Tags: <smartgroups><cache>
Title: Smart Groups - cannot get smart groups to refresh
ThreadText: # Smart Groups - cannot get smart groups to refresh
  
  (Asked by: username_0 on 2016-07-06)
  
  I have read as much as I can about smart groups but I am having problems that I am not able to solve. I have a smart group which shows the same SQL as an Advanced Search but they produce different results.
  
  [![The Smart Group displays the criteria and the number of items selected being 25](https://i.sstatic.net/7lTEE.jpg)](https://i.sstatic.net/7lTEE.jpg)
  
  [![The same query using a separate Advanced Search displays 31 items](https://i.sstatic.net/1gztz.jpg)](https://i.sstatic.net/1gztz.jpg)
  
  If I refresh the smart group cache I get the same result.
  
  **Tags:** smartgroups, cache
  
  > **Comments:**
  > **username_1**: Perhaps it maybe related with this [There is some inconsistent/confusing workflow managing contacts from smart groups?](http://civicrm.stackexchange.com/questions/15416/there-is-some-inconsistent-confusing-workflow-managing-contacts-from-smart-group)  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2019-02-04. Score: 2
  
  Some clarification about 'getting smart groups to refresh'
  
  I assume you are using the button 'update smartgroup counts' from the Manage groups screen. This could perhaps be better called 'calculate missing smartgroup counts' (although that wouldn't fit on the button.....) - that button causes the count to be calculated for all groups that the cache has not been built for.
  
  Groups are only recalculated if they have aged out - by default the smart group timeout is 5 minutes. Pretty much whenever you save a contact it attempts to delete the cache for any smart groups that are more than those 5 minutes old (you can set the cache to less than 5 minutes or 0 for more caching). It will then re-fill the cache for that group next time you access it.
  
  If you barely ever edit contacts I guess the cache might not get cleared as often as it 'should' - you can schedule a job (Job.group\_cache\_flush) to run however often you want - if you do this it makes sense to set the setting 'smart\_group\_cache\_refresh\_mode' to 'deterministic' to stop it from also clearing on contact edit (note that this is often good to do for performance reasons)
  
  
  ---
  
  ### Answer by username_3 on 2017-07-02. Score: 1
  
  This answer was a comment by Joanne which I think deserved to be an answer
  
  > I have tested this on 4.7.12 and found that Rebuild Smart Group Cache might not remove the contact whose criteria no longer comply with the smart group but Administer > System Settings > Cleanup Caches and Update Paths > Cleanup Caches does. So it seems to be a cache issue rather than a problem with the underlying smart group functionality
  
  > **Comments:**
  > **username_4**: I have the same problem (tested on 5.8.2 and 5.9.1) : when I select Individuals via Advanced Search, I get 19 results, while, when I modify an existing Smart Group towards the same criteria, I get only 9 in the Search, thus in the modified Smart Group. This is really bothering, because I have embedded smart Groups.  
  > **username_4**: I don't think it is just a cache issue : the problem occurs at the Search phase (before updating the Smart Group)  
  
  ---
  
  ### Answer by username_5 on 2016-07-06. Score: 0
  
  I think you have a participant/event item in there - so that means some of your Contacts would have participated in more than one event!
  
  Try:
  Search Builder - it only returns the Contacts (unique)
  
  > **Comments:**
  > **username_0**: I have rebuilt the filter using Search Builder and correctly obtain a dataset of 31 contacts. I have created a Smart Group from this dataset. If I now add a contact with the criteria to satisfy the smart group and view the smart group, the new contact appears in the smart group. However if I now change the criteria on the newly created contact so that it does not comply with the smart group it remains in the smart group. If I run the job Rebuild Smart Group Cache the smart group continues to contain the contact whose criteria no longer comply with the smart group.  
  > **username_1**: I'm having a similar issue. Are you found some solution?  
  > **username_6**: I can reproduce similar problems whereby a smartgroup that is based on a date range is not refreshed when another contact should meet the date criteria  
  > **username_7**: @MartinFuggle I have tested this on 4.7.12  and found that Rebuild Smart Group Cache might not remove the contact whose criteria no longer comply with the smart group but Administer > System Settings > Cleanup Caches and Update Paths > Cleanup Caches does. So it seems to be a cache issue rather than a problem with than the underlying smart group functionalility.  
  > **username_3**: That last comment deserves to be an answer imo  
  > **username_4**: Moreover, if I remove all the search criteria from my Smart Group, I get only 15 Contacts in the search (against 1787 in my Data Base)  
  
  ---
  
  ### Answer by username_4 on 2019-02-04. Score: 0
  
  I think there is a bug : I could reproduce it on the demo site :
  
  * Create a group : TEST
  * Advance search Individuals whose name contains
    "Adam" > You get 12 instances > Create smart group G1 under TEST
  * Advance search Individuals whose name contains "ck" > You get 8
    instances > Create smart group G2 under TEST
  * Advance search
    Individuals whose name contains "y" > You get 52 instances > Create
    smart group G3 under TEST
  * Advance search Groups G1, G2, G3 > You get
    70 (you could expect 72, but there are some common results) > Create
    smart group "Total" under TEST
  
  Now,
  
  * open G1 and modify search criteria : "Ad" instead of "Adam" > you get 18 instances (instead of 12), thus 6 more > Update the smart group
  * Open group "Total" > you get 77 instead of 70, thus 7 more : why 7 and not 6 ?
  
  Now again,
  
  * open G1 again and modify search criteria : "d" instead of "Ad" > You get 71 instances (instead of 18, thus a lot more) > Update the smart Group
  * Open group "Total" > you still get 77 (while it should contain much more than that)
  * Open "test" > you get 104 while there is no reason why it should be different from "Total" result
  
  I have just openned an issue : <https://lab.civicrm.org/dev/core/issues/694>
  
  
  ---
  
  