• Resolved longnha

    (@longnha)


    Hi,

    I use shortcode to display popular posts and set data caching to 1 hour. The popular posts list fast loading when it retrieves from cache, but took around 1 to load the query if it need to refresh the caches.

    SELECT SUM(pageviews) AS total
    FROM wp_popularpostssummary v
    LEFT JOIN wp_posts p
    ON v.postid = p.ID
    WHERE p.post_type IN('post')
    .....

    Is there any suggestion to speed it up please? I’m thinking about a cronjob to run the query, like each 30 mins but not sure to do it yet!

    Thank you for your input.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @longnha,

    Please have a look at the Performance wiki page, it contains general recommendations / suggestions that may be of help.

    Thread Starter longnha

    (@longnha)

    Yeah, I’ve already applied the recommendation and the performance is good, except for when the cache expired and new query is made, it took way too long.

    Plugin Author Hector Cabrera

    (@hcabrera)

    What “recommendation” did you apply exactly? The wiki page includes a few of them.

    Thread Starter longnha

    (@longnha)

    I have object caching enabled, using InnoDB.

    The query, for example:

    SELECT v.view_date, SUM(v.pageviews) AS pageviews
    FROM wp_popularpostssummary v
    INNER JOIN wp_posts p
    ON v.postid = p.ID
    WHERE (v.view_datetime BETWEEN '2024-03-09 00:00:00'
    AND '2024-03-15 23:59:59')
    AND p.post_type IN ('post')
    AND p.post_status = 'publish'
    AND p.post_password = ''
    GROUP BY v.view_date
    ORDER BY v.view_date DESC;

    It takes over 1 min to load.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Given the information you have provided so far (just a couple of queries and that’s it, not even some actual data like hardware specs, database table sizes, etc.) if I had to take a guess then:

    (All these suggestions / recommendations are mentioned on the Performance wiki page I shared earlier by the way, I’m just summarizing it here.)

    Thread Starter longnha

    (@longnha)

    The wp_popularpostssummary is around 2G. So, I cleared the cache, set log limit to 7 days and enabled Sample Rate = 100. The page did load faster at first but as the data size increase, the load time is increased too.

    The site is on dedicated server but I’m not familiar with mySQL so not sure how to tune it for faster JOIN query!

    Also, I guess a lot of views are from Bots like Google. Can I exclude it from the count?

    Thank you.

    Thread Starter longnha

    (@longnha)

    And it would speed everything up a bit if there is ability to exclude the comments from tracking as some sites does not have comment enabled.

    Plugin Author Hector Cabrera

    (@hcabrera)

    The wp_popularpostssummary is around 2G. So, I cleared the cache, set log limit to 7 days and enabled Sample Rate = 100. The page did load faster at first but as the data size increase, the load time is increased too.

    That’s to be expected. The server will always require time to load stuff from the database, and the database will continue to grow as you add more data to it over time.

    Limiting WPP’s views data to last 7 days only should help though. If you don’t need older views data then you should be good to go now.

    If you’re still seeing slow database responses after clearing WPP’s database tables then I would suggest reviewing your entire site, something else is slowing down your site’s performance.

    I’m not familiar with mySQL so not sure how to tune it for faster JOIN query!

    The query itself is already optimized, WPP’s database tables even use indexes to help speed things up.

    If your database server is still struggling then you have a problem somewhere else (see previous comment).

    And it would speed everything up a bit if there is ability to exclude the comments from tracking as some sites does not have comment enabled.

    The plugin doesn’t “track” comments though? Comments are a built-in WordPress feature, and the plugin will use the existing comments data only when sorting popular posts by comments count.

    If you’re sorting posts by views count (which is the default behavior) then comments data is irrelevant and shouldn’t impact performance.

    Thread Starter longnha

    (@longnha)

    Thank you for the info @hector.

    Also, does the plugin count view from Bots such as GoogleBot?

    Thanks.

    Plugin Author Hector Cabrera

    (@hcabrera)

    It should exclude most bots AFAIK since the plugin updates views count via AJAX. Most bots out there won’t run JS code since all they care about is crawling pages to extract content.

    Googlebot I believe is capable of running JS though so there might be some hits coming from it. I can’t say for sure. The plugin doesn’t really know whether a page view is generated by a human or a bot, that would imply some sort of data collection which isn’t great for GDPR for example.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Display Popular Posts Performance Issue’ is closed to new replies.