Very slow query when fetching popular posts

Posted in: Newspaper
Post count: 84

Hi There,

I have added a block to show the most popular posts on the post detail template’s sidebar:
Example: https://jornaldoalgarve.pt/psd-quer-saber-o-que-se-passa-no-bloco-de-partos-em-portimao/

The same block is also on the homepage and other pages.

I immediately started noticing a very high CPU server usage, and it got confirmation that the cause is the query blocks, mainly the popular posts.

https://drive.google.com/file/d/1cPzMqjT9NeCaHfi88XqVoWFvqJ7HBEkQ/view?usp=sharing
https://drive.google.com/file/d/1cYa48GSzxGpHf_lG8n_1xJeyCcfGFFH-/view?usp=sharing

We are currently running:
– Object cache (Redis)
– Database cache (Memcached)
– Page cache
– Cloudflare

Server:
VPS with 8GB of ram and 4 cores

The issue is every time a non-cached page gets served, the CPU usage increases immensely.

Is there any issue with this block? If not, is there any way to make it use fewer resources?

Thanks

Post count: 35449

Hi,
This problem usually occurs when there are many posts on the site, then this filter must go through all the posts to find the most popular, an alternative would be to use this filter for the last day, or 2 days or the last week, in this way the request should be faster -> https://i.imgur.com/OsJPkbi.png (or better, use a different filter that do not need to check all the posts).
Thank you!

Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newspaper’ is closed to new topics and replies.