STRML
Forum Replies Created
-
Dealt with this earlier. I was getting load times of up to 30s for admin pages, less than 1s with WOOCS/FOX disabled.
The issue was the use of “PHP Session” for Currency Storage in the Options menu (WooCommerce -> Settings -> Currency -> Options).
Switching it to Redis worked on my hosting and sped up the site considerably. If you don’t have Redis or Memcached, try Transient Storage.Apologies, there was an error in the original patch re: groupby_sql. I have removed that error:
From 4c0f8e1146be31bec6a035c60aa2886695fb4c9b Mon Sep 17 00:00:00 2001 From: Samuel Reed <[email protected]> Date: Wed, 12 Oct 2016 13:03:48 -0500 Subject: [PATCH] fix(EM): Monkey patch count() to reduce unnecessary queries on 5.6.6.1 --- .../plugins/events-manager/classes/em-events.php | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/wp-content/plugins/events-manager/classes/em-events.php b/wp-content/plugins/events-manager/classes/em-events.php index e3fedfb..82095da 100644 --- a/wp-content/plugins/events-manager/classes/em-events.php +++ b/wp-content/plugins/events-manager/classes/em-events.php @@ -34,22 +34,31 @@ class EM_Events extends EM_Object { $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : ''; $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : ''; $groupby_sql = ''; + $orderby_sql = ''; //Get the default conditions $conditions = self::build_sql_conditions($args); //Put it all together $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):''; + if( $count ){ + $selectors = 'COUNT(*)'; + $limit = ''; + $offset = ''; + $join = ''; + } else { + $join = "LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id"; + //Get ordering instructions $EM_Event = new EM_Event(); $EM_Location = new EM_Location(); $orderby = self::build_sql_orderby($args, array_keys(array_merge($EM_Event->fields, $EM_Location->fields)), get_option('dbem_events_default_order')); + //Now, build orderby sql $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : ''; - //Create the SQL statement and execute - - if( !$count && $args['array'] ){ + //Build groupby + if( $args['array'] ){ $selectors_array = array(); foreach( array_keys($EM_Event->fields) as $field_selector){ $selectors_array[] = $events_table.'.'.$field_selector; @@ -57,23 +66,17 @@ class EM_Events extends EM_Object { $selectors = implode(',', $selectors_array); }elseif( EM_MS_GLOBAL ){ $selectors = $events_table.'.post_id, '.$events_table.'.blog_id'; $groupby_sql[] = $events_table.'.post_id, '. $events_table.'.blog_id'; }else{ $selectors = $events_table.'.post_id'; $groupby_sql[] = $events_table.'.post_id'; //prevent duplicates showing in lists } - if( $count ){ - $selectors = 'SQL_CALC_FOUND_ROWS *'; - $limit = 'LIMIT 1'; - $offset = 'OFFSET 0'; } //add group_by if needed $groupby_sql = !empty($groupby_sql) && is_array($groupby_sql) ? 'GROUP BY '.implode(',', $groupby_sql):''; + //Create the SQL statement and execute $sql = apply_filters('em_events_get_sql'," SELECT $selectors FROM $events_table - LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id + $join $where $groupby_sql $orderby_sql $limit $offset @@ -81,8 +84,7 @@ class EM_Events extends EM_Object { //If we're only counting results, return the number of results if( $count ){ - $wpdb->query($sql); - return apply_filters('em_events_get_count', $wpdb->get_var('SELECT FOUND_ROWS()'), $args); + return apply_filters('em_events_get_count', $wpdb->get_var($sql), $args); } $results = $wpdb->get_results( $sql, ARRAY_A); -- 2.10.0Forum: Plugins
In reply to: [Broadcast] Very Large Queries – Being KilledThanks for the reply.
Just wanted to see if there was any way we could trim this down or otherwise re-use the query that generates that giant ID array to cut down on the size of the actual executed query.
WPEngine is involved just because of their little query cop. I agree they’re not an ideal host by any means.