diff --git a/includes/class-calendar-plus-dates-generator.php b/includes/class-calendar-plus-dates-generator.php index 3fbb5bf..4b81db3 100644 --- a/includes/class-calendar-plus-dates-generator.php +++ b/includes/class-calendar-plus-dates-generator.php @@ -278,6 +278,10 @@ public static function delete_old_dates( $delete_from = false ) { update_option( 'calendarp_first_date_generated', $delete_from ); self::clear_cached_months(); } + + // Lets use this opportunity to store the last known total dates + $total_old_dates = (int) $wpdb->get_var( "SELECT COUNT(ID) FROM $table" ); + update_option( 'calendarp_last_known_total_dates', $delete_from ); } diff --git a/includes/class-calendar-plus-query.php b/includes/class-calendar-plus-query.php index 27bc2f3..6615d66 100644 --- a/includes/class-calendar-plus-query.php +++ b/includes/class-calendar-plus-query.php @@ -6,7 +6,14 @@ class Calendar_Plus_Query { public function __construct() { - $this->query_vars = array( 'from', 'to', 'location', 'calendarp_searchw', 'order' ); + $this->query_vars = array( 'location', 'calendarp_searchw', 'order' ); + + // "to" and "from" query vars can lead to heavy queries, lets only allow them if total dates is below the limit + $last_known_total_dates = (int) get_option( 'calendarp_last_known_total_dates', 0 ); + if( $last_known_total_dates < apply_filters( 'calendarp_heavy_query_vars_total_dates_limit', 500 ) ) { + $this->query_vars[] = 'from'; + $this->query_vars[] = 'to'; + } if ( ! is_admin() ) { add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );