• Resolved Darko G.

    (@darkog)


    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;
    }
    • This topic was modified 5 years, 1 month ago by Darko G..
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Thomas Maier

    (@webzunft)

    Hi Darko,

    thanks for taking the time to make this suggestion. I really appreciate it.

    I am constantly monitoring the number of requests and am not seeing this particular query on my installation. Where did you take the screenshot?

    Thanks,
    Thomas

    Thread Starter Darko G.

    (@darkog)

    Hi @webzunft

    This is probably unique case when no ads are found by the query and it is repeated, you are not setting cache when there are no ads found by the query, so therefore it is executed again later when called.

    Also, the site i took the screenshot is in the screenshot see the Query column.

    Thanks,
    Darko

    • This reply was modified 5 years, 1 month ago by Darko G..
    Plugin Author Thomas Maier

    (@webzunft)

    Hi Darko,

    I am still trying to reproduce it without success.

    I tried using a group with one or more ad and a content placement.

    Are you using any add-ons for Advanced Ads or could you check if this is caused by another plugin?

    Thanks,
    Thomas

    Plugin Author Thomas Maier

    (@webzunft)

    Hi Darko,

    I tested a few scenarios and am still not able to get this query to appear multiple times.

    Do you happen to have a test site where you could try to decrease the number of ads to see when this duplicate query stops? Maybe that could help.

    Thanks,
    Thomas

    Plugin Author Thomas Maier

    (@webzunft)

    Hi @darkog,

    we were able to reproduce and fix the issue.

    If you run your current change then just keep it until the next update. Otherwise, reach out for the beta.

    Best regards,
    Thomas

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Performance Issue and possible solution’ is closed to new replies.