Server scaling and load created by the plugin

The times are in seconds. I initially wrote ms.

You could, it is what… 3x faster? But 0.047s isn’t very much time. I guess it would only matter for lots of comments, you could try testing with 100 comments rather than 9.

Having the comments templates set up the way they are now makes it a lot easier for people to customize them than it would if they were changed to more standard HTML templates - because they can use template tags instead of having to access properties of the post object. So unless it’s really a problem, it’s better to keep it as it is.

Looking at @steve_pd’s site, the issue seems to be comment numbers on index pages. Using a webhook for that works quite well. The only problem I’m finding with it is that if it’s added to the plugin, it’s not possible to sync existing posts with Discourse topics until either someone adds a new comment to a topic, or the WordPress post is republished to Discourse.

@steve_pd I see something that’s probably causing the plugin to use a lot of resources on your site. Because syncing comment numbers with Discourse is very inefficient, I set the plugin to use a longer sync period (defaults to 1 day) for archive pages than it does for single posts. The problem is that this is only being applied to post archives, it’s not applied to pages. This means that pages (as opposed to posts) on your site that contain lists of posts that are displaying comment numbers are making many calls to Discourse.

To fix this:

  • a filter can be added to the plugin’s get_comments_number function so that pages as well as posts can use the longer sync period

  • a new, more efficient, function can used to get the comment numbers from Discourse

  • an option can be added to the plugin to sync comment numbers with a webhook

The first two items can be added to the plugin right away. The last one probably won’t make it into the next update, but should be available soon.

2 Likes

Sounds good, although can we ensure wwhichever page is selected as the front page is overridden?

For sites built using stuff like Visual Composer you’ll always find the posts page is a page, rather than a normal part of the loop. Daily comment number updates there would be problematic.

1 Like

Another approach to syncing comment numbers is to put together the data on the Discourse end. To try it out, I installed the Data Explorer plugin and wrote a query to select topics that have a topic_embed and have been updated in the last 10 minutes. I wrote a WordPress function to run the Data Explorer query no more often than every 10 minutes and use the data it returns to update the comment numbers.

The benefits of doing it this way over using a webhook are that to handle the webhook request requires reloading the entire WordPress environment, and that there’s no way of limiting the number of requests made through a webhook.

The only problem with using the Data Explorer plugin for this is that I don’t think it’s possible to send any parameters with the Data Explorer request. It would be useful to be able to send a last_synced parameter. Maybe a Discourse plugin could be written that would do something similar, but accept a time parameter?

Possibly a similar approach could be used for syncing the comments content.