[wp-trac] [WordPress Trac] #41281: attachment_url_to_postid results in very slow query

WordPress Trac noreply at wordpress.org
Tue Feb 13 17:45:59 UTC 2018


#41281: attachment_url_to_postid results in very slow query
------------------------------+------------------------------
 Reporter:  Takahashi_Fumiki  |       Owner:
     Type:  enhancement       |      Status:  new
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Database          |     Version:  4.9
 Severity:  normal            |  Resolution:
 Keywords:                    |     Focuses:  performance
------------------------------+------------------------------

Comment (by markjaquith):

 @Takahashi_Fumiki — thanks for this ticket!

 I ran into this issue today. Client has a lot of images hotlinked to their
 CDN that will not resolve to a post ID. A lot of AMP or FaceBook Instant
 Articles plugins run `attachment_url_to_postid()` on images found in
 posts, to optimize them for those formats. When your postmeta table is
 large, this query is slow.

 There's no hook that lets you bail before that query gets run, so I nuked
 it at a really low level (BE CAREFUL WITH THE `query` HOOK).

 https://gist.github.com/markjaquith/2c8c29a0ccd2916520e5b71fcec626ca

 We could solve this in WordPress core a few ways.

 1. Make the query faster, with an index.
 2. Cache the results of these lookups.
 3. Whitelist domains that we do the lookups for.

 Or some combination of those.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41281#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list