Skip Navigation

[Resolved] Query performance problem

This thread is resolved. Here is a description of the problem and solution.

Problem: I am using Query Monitor to investigate my site's performance. It seems like the wpcf_image_is_attachment function is causing a bottleneck in query performance on my site. What are the implications of the option "add resized images to library"? In general do you have better performance when the option is checked?

Solution:
In general, you will have better performance with "add resized images to library" active because after the resized image has been rendered once it's saved to the library for future use. The server does not need to calculate and generate a resized image on each page load - it stores a reference to the image in your database and loads the resized image from the uploads folder. This creates an image attachment link in the database, so if you add 10 resized images to each post your database queries of image attachments will be incrementally slower as it needs to sort through more records.

When testing performance, we try to ensure that no single query takes longer than 0.5ms. If you have any single query that takes longer than 0.5ms, then we should try to investigate that query.

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Guillaume 6 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#595313
Capture d’écran 2017-12-02 à 15.58.18.png

Hello,

I use Toolset for years and now my website is almost build with your plugins only.

Recently I noticed some bad performances so I installed Query Monitor and you can see that View is the problem of my bad performances

wpcf_image_is_attachment() is a big problem because I understand that this query is used to found an image that will be displayed on the page, but I noticed that some queries are looking for images that are not in loaded the page.

My posts have post-type childs, and while I want to display the post only, the queries wpcf_image_is_attachment() are looking for the images of all the childs while they are not called.

For exemple :

SELECT ID
FROM p2u_posts
WHERE post_type = 'attachment'
AND guid='hidden link'
LIMIT 1

That query took 0,2174sec to load while the image is not visible on that page.

Do you know if I can speed up my website ?

Thanks

#595404

Hi, can you include more information about your View so I can investigate?
- Take some screenshots that show the View editor screen in wp-admin so I can see your settings, and add those images in your reply here.
- Are you using any nested Views inside the parent post type View? If so, please take screenshots of the nested Views as well.
- How is the image hidden link added to a child post? Is it a custom field, or in the post content, or a featured image, etc?

I'll take a look and see what we can do to help speed things up.

#595452
Capture d’écran 2017-12-04 à 02.23.04.png
Capture d’écran 2017-12-04 à 01.32.12.png
Capture d’écran 2017-12-04 à 01.33.48.png
Capture d’écran 2017-12-04 à 01.35.40.png
Capture d’écran 2017-12-04 à 01.39.23.png
Capture d’écran 2017-12-04 à 01.41.26.png
Capture d’écran 2017-12-04 à 02.12.11.png

Thanks for your reply.

The way I use Toolset may be a little bit complex and I need to explain how I use it.

I have posts, each post have childs that are products to affiliate websites. I need to add an affiliate link in a field to redirect the visitor to the product. Those links need to be cloaked to be understood by the affiliate plateform that I'm the referral.

ex : hidden link
where XXXXXXXXXXXXX is what I enter in the field in the child post

So I use a template to create the affiliate links. If website is AAAA so use this cloaked link structure, if the affiliate website is BBBB so use that cloaked link structure.

I tried to explain all in the screenshot joined.

--------------------------

Moreover I tried the option "add resized images to library", It solved a part of the problem because the wpcf_image_is_attachment() queries are not asked anymore but view is still the plugin that load the more content.

You will see the difference of perf in the screenshot liked. I added another screenshot of the slowest queries to know if its normal or not.

What are the incidences of the option "add resized images to library" ? In general do you have better performances when the option is cheked ?

Thanks

#595658

What are the incidences of the option "add resized images to library" ? In general do you have better performances when the option is cheked ?
In general yes, you will have better performance because after the resized image has been rendered once it's saved to the library for future use. The server does not need to calculate and generate a resized image on each page load - it stores a reference to the image in your database and loads the resized image from the uploads folder. This creates an image attachment link in the database, so if you add 10 resized images to each post your database queries of image attachments will be incrementally slower as it needs to sort through more records. That's the trade-off.

It solved a part of the problem because the wpcf_image_is_attachment() queries are not asked anymore but view is still the plugin that load the more content.
When testing performance, we try to ensure that no single query takes longer than 0.5ms. If you have any single query that takes longer than 0.5ms, then we should try to investigate that query. Looking at the total time spent by all queries per component isn't always helpful, because the optimization of queries also depends on how your Views are structured. For example, in your "homepage template" image, I can see that you use id="$parent" to get the featured image of the parent post in each loop iteration. To get parent information in a loop showing child posts, WordPress must make another query in each iteration of the loop. This isn't optimal, but unfortunately it's unavoidable when you need to access data from another post within the loop of a View.

#596550

OK it's clear.
Thanks for your reply.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.