SQL_Calc_found crashing website
-
Our database has around 15,000 posts. And since 3 days the website crashes almost every hour. The problem is Select_Calc_found query.
I added the following queries
[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]
add_filter('pre_get_posts', 'optimized_get_posts', 100); function optimized_get_posts() { global $wp_query, $wpdb; $wp_query->query_vars['no_found_rows'] = 1; $wp_query->found_posts = $wpdb->get_var( "SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')" ); $wp_query->found_posts = apply_filters_ref_array( 'found_posts', array( $wp_query->found_posts, &$wp_query ) ); $wp_query->max_num_pages = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']); return $wp_query; } function no_rows_found_function($query) { if (!is_admin()) { $query->set( 'no_found_rows', true ); } } add_action('pre_get_posts','no_rows_found_function');
The crashing has stopped. I got these from posts which are 5 years old.
But I couldn’t find any recent posts that could help resolve the issue. Our database is going to grow more. Should I just stick to this solution or is there more I have to do to stop the website from crashing in the future.Any help or suggestion would be of great help.
And more over this solution has caused problem to pagination in the website. What should I do regarding this? Please help
- The topic ‘SQL_Calc_found crashing website’ is closed to new replies.