Answers.Body: <p>As Coleman commented correctly, this is a case for a ticket.
  <a href="https://lab.civicrm.org/dev/core/-/issues/5518" rel="nofollow noreferrer">https://lab.civicrm.org/dev/core/-/issues/5518</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-10T11:29:27.753Z
Answers.LastActivityDate: 2024-10-10T11:29:27.753Z
Answers.UserDisplayName: nielo
Body: <p>We have about 2300 groups. When civicrm prepares the modal confirm form to delete a group it checks all smart groups if they may rely on the group to be deleted. It seems that there ist no applicable api4 where clause to exactly get those groups. So all smart groups are fetched and then a array_filter is applied, see lines from</p>
  <pre><code> […]
   foreach ($groups as $group) {
        // Filter out arrays in Form Values which are group searchs.
        $groupSearches = array_filter(
          $group['saved_search_id.form_values'],
          function($v) {
            return ($v[0] == 'group');
          }
        );
   […]
  </code></pre>
  <p><a href="https://lab.civicrm.org/dev/core/-/blob/master/CRM/Contact/BAO/SavedSearch.php?ref_type=heads#L391" rel="nofollow noreferrer">https://lab.civicrm.org/dev/core/-/blob/master/CRM/Contact/BAO/SavedSearch.php?ref_type=heads#L391</a></p>
  <p>The whole function takes minutes on our site and this filter sometimes takes 1.5 seconds.</p>
  <p>I tried everything to optimize this behaviour, read about performance of array_filter, tried different checks in the callback but without luck.</p>
  <p>Can anybody with slightly more experience here shed some light on this?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-09T11:34:32.980Z
Comments.Text: Yeesh, that function isn't even correct anymore, because lots of smart groups these days use `api_params` instead of `form_values`.
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-09T16:31:14.980Z
Comments.Text: Okaaayyy, thx Coleman, what can I do? Nay ideas how to easier identify the groups?
Comments.UserDisplayName: nielo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-10T01:57:23.120Z
Comments.Text: It would be helpful to open a ticket on lab.civicrm.org
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-10T11:28:39.427Z
Comments.Text: You're right, I did.
Comments.UserDisplayName: nielo
Tags: <groups><smartgroups>
Title: PHP Devs and gurus: any idea how to accelerate CRM_Contact_BAO_SavedSearch->getSmartGroupsUsingGroup()?
ThreadText: # PHP Devs and gurus: any idea how to accelerate CRM_Contact_BAO_SavedSearch->getSmartGroupsUsingGroup()?
  
  (Asked by: username_0 on 2024-10-08)
  
  We have about 2300 groups. When civicrm prepares the modal confirm form to delete a group it checks all smart groups if they may rely on the group to be deleted. It seems that there ist no applicable api4 where clause to exactly get those groups. So all smart groups are fetched and then a array\_filter is applied, see lines from
  
  ```
   […]
   foreach ($groups as $group) {
        // Filter out arrays in Form Values which are group searchs.
        $groupSearches = array_filter(
          $group['saved_search_id.form_values'],
          function($v) {
            return ($v[0] == 'group');
          }
        );
   […]
  
  ```
  
  <https://lab.civicrm.org/dev/core/-/blob/master/CRM/Contact/BAO/SavedSearch.php?ref_type=heads#L391>
  
  The whole function takes minutes on our site and this filter sometimes takes 1.5 seconds.
  
  I tried everything to optimize this behaviour, read about performance of array\_filter, tried different checks in the callback but without luck.
  
  Can anybody with slightly more experience here shed some light on this?
  
  **Tags:** groups, smartgroups
  
  > **Comments:**
  > **username_1**: Yeesh, that function isn't even correct anymore, because lots of smart groups these days use `api_params` instead of `form_values`.  
  > **username_0**: Okaaayyy, thx username_1, what can I do? Nay ideas how to easier identify the groups?  
  > **username_1**: It would be helpful to open a ticket on lab.civicrm.org  
  > **username_0**: You're right, I did.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-10-10. Score: 1
  
  As username_1 commented correctly, this is a case for a ticket.
  <https://lab.civicrm.org/dev/core/-/issues/5518>
  
  
  ---
  
  