From: Steve Sutton Date: Fri, 12 Jan 2018 18:02:30 +0000 (-0500) Subject: Help with too many queries on same thing. X-Git-Tag: v2.10.23^2~23^2~5 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c3d0c75f8437ef42acea353c3a66347fc5e0a36c;p=WP-Plugins%2Fglm-member-db.git Help with too many queries on same thing. stashing the search array. --- diff --git a/setup/frontHooks.php b/setup/frontHooks.php index d9e1fe07..a47d45b3 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -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 '
$where: ' . print_r( $where, true ) . '
'; // 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;