Performance Issue and possible solution
-
Hello,
We found out that your plugin makes duplicate SQL queries with Query Monitor and therefore it terribly affects our performance.
Proof: https://prntscr.com/pj07t6
I modified the WP_Query call to properly use WP Object Cache which eliminates the duplicate SQL queries.
Please review and implement because this is crucial for some sites that are aimed for performance.
Solution as follows:
/** * load all public ads for this group * * @since 1.0.0 * @update 1.1.0 load only public ads * @update allow to cache groups for few minutes * @return arr $ads array with ad (post) objects */ private function load_all_ads() { if ( ! $this->id ) { return array(); } // reset $this->ads = array(); // much more complex than needed: one of the three queries is not needed and the last query gets slow quiet fast $args = array( 'post_type' => $this->post_type, 'post_status' => 'publish', 'posts_per_page' => -1, 'taxonomy' => $this->taxonomy, 'term' => $this->slug, 'orderby' => 'id' // might want to avoid sorting as not needed for most calls and fast in PHP; slight I/O blocking concern ); $key = 'ad_group_all_ads_' . $this->post_type . '_' . $this->taxonomy . '_' . $this->slug; $ads = wp_cache_get( $key, Advanced_Ads_Model::OBJECT_CACHE_GROUP, false ); if ( FALSE === $ads ) { $ads = new WP_Query( $args ); if ( $ads->have_posts() ) { $this->ads = $this->add_post_ids( $ads->posts ); } wp_cache_set( $key, $this->ads, Advanced_Ads_Model::OBJECT_CACHE_GROUP, Advanced_Ads_Model::OBJECT_CACHE_TTL); } else { $this->ads = $ads; } return $this->ads; }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Performance Issue and possible solution’ is closed to new replies.