Hi there!
I’m not a user of the plugin nor am I looking for support but I wanted to share some notes from some recent triaging that I recently posted on Performance issues, attachment_url_to_postid | WordPress.org
Essentially, the plugin appears to have a feature that can have a severe impact on a site’s performance.
I believe this may be the image locking feature I’ve seen referenced but I haven’t reviewed your plugin’s options in detail yet, just its behavior.
It might be good to review other more performant and optimized options for achieving the feature’s goal.
Extended details
I’ve recently triaged a case where a site was experiencing some performance issues. The site was making excessive database queries, leading to very slow requests and throttling.
After examining things closer, we found that every image on each page and post were leading to a query for the image and various subsizes, like the following.
SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = '2022/03/example-image.jpg'
SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = '2022/03/example-image-300x163.jpg'
SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = '2022/03/example-image-200x108.jpg'
SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = '2022/03/example-image-400x217.jpg'`
Examining the stack trace for these requests led to this:
Patreon_Compatibility->jetpack_photon_skip_image, attachment_url_to_postid
I see the plugin has a compatibility fixer to try to identify gated images and disable the Jetpack Photon Image CDN for them.
Note that this may lead to severe performance issues on sites with a lot of images and traffic. This can slow down a site, lead to throttling from a host, and cause a site to hit PHP connection limits. More affordable hosting options may encounter significant database load.
Other plugins have struggled with similar issues. Some users work around this by adding a custom index.
- Core discussion: #41281 (attachment_url_to_postid results in very slow query) – WordPress Trac
- Example issue with Yoast: Query with meta_value slowing down database · Issue #10195 · Yoast/wordpress-seo · GitHub
It may be worth reviewing further and finding a more optimized solution.