[wp-trac] [WordPress Trac] #52759: Add a filter to get_available_post_mime_types() function to allow overriding extremely slow query.

WordPress Trac noreply at wordpress.org
Wed Mar 10 22:44:43 UTC 2021


#52759: Add a filter to get_available_post_mime_types() function to allow
overriding extremely slow query.
----------------------------------------+------------------------------
 Reporter:  maciejmackowiak             |       Owner:  (none)
     Type:  feature request             |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  Media                       |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  needs-patch good-first-bug  |     Focuses:  performance
----------------------------------------+------------------------------

Comment (by archon810):

 +1 for this.

 For us, it adds an additional 0.35s or so (right now, more if db is
 loaded).


 {{{
 SELECT SQL_NO_CACHE DISTINCT post_mime_type
 FROM wp_posts
 WHERE post_type = 'attachment'
 > OK
 > Time: 0.35s
 }}}

 On the grid view it is called from here:
 https://github.com/WordPress/WordPress/blob/785cb6cc7d4d17ef0aa16b187dcfb6a8dc513e1b
 /wp-admin/includes/class-wp-media-list-table.php#L97

 It calls this function:
 https://github.com/WordPress/WordPress/blob/00680f2e89766e4ac9a71c68a8cccd3a141afb34
 /wp-admin/includes/post.php#L1287

 And here is the query:
 https://github.com/WordPress/WordPress/blob/bf83c368fdfcee2b879d00b193f505038e1681f0
 /wp-includes/post.php#L7517

 We were able to cache and greatly speed up this query already:
 {{{
 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
 FROM wp_posts
 WHERE post_type = 'attachment'
 AND post_status != 'auto-draft'
 AND post_status != 'trash'
 ORDER BY post_date DESC
 }}}
 and I hope with the new proposed filter, we will be able to speed up the
 site even more.

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


More information about the wp-trac mailing list