Help with too many queries on same thing.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 12 Jan 2018 18:02:30 +0000 (13:02 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 12 Jan 2018 18:02:30 +0000 (13:02 -0500)
stashing the search array.

setup/frontHooks.php

index d9e1fe0..a47d45b 100644 (file)
@@ -413,8 +413,12 @@ function is_member( $id = false ) {
      * @return array Array of categories
      * @access public
      */
-add_filter('glm_getListForSearch', function( $field,$cat_parent = false, $forActiveMembers = true ){
-
+add_filter('glm_getListForSearch',
+    function( $field, $cat_parent = false, $forActiveMembers = true ){
+        static $searched = array();
+        if ( isset( $searched[$field] ) && isset( $searched[$field][$cat_parent] ) ) {
+                return $searched[$field][$cat_parent];
+            }
         $where = '';
         $member_category = false;
         $parent_id = 'null';
@@ -438,7 +442,7 @@ add_filter('glm_getListForSearch', function( $field,$cat_parent = false, $forAct
         }
 
         if($cat_parent !== false){
-            $sql = 'SELECT id FROM '.GLM_MEMBERS_PLUGIN_DB_PREFIX."categories WHERE name = '$cat_parent';";
+            $sql = 'SELECT id FROM '.GLM_MEMBERS_PLUGIN_DB_PREFIX."categories WHERE name = '$cat_parent'";
             $parent_id = $this->wpdb->get_var($sql);
         }
         // If we only want fields for active and visible members
@@ -462,8 +466,10 @@ add_filter('glm_getListForSearch', function( $field,$cat_parent = false, $forAct
                    AND M.id = MI.member AND T.$field = C.id AND C.parent = '$parent_id' GROUP BY T.$field, C.name
             ";
         }
+        // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
         // Get a list of all fields (optionally for active members only)
         $search_fields = $this->wpdb->get_results($where, ARRAY_A);
+        $searched[$field][$cat_parent] = $search_fields;
 
         return $search_fields;