[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 11:32:58 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:  General          |    Version:
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 On sites sites with lot of posts the query used in
 get_available_post_mime_types is extremely slow.
 It would be nice to have a filter that will allow us to override this
 query and for example cache the results.

 It could be something simillar to this filter:
 https://core.trac.wordpress.org/browser/tags/5.6/src/wp-
 includes/media.php#L4172

 {{{#!php
 <?php
 function get_available_post_mime_types($type = 'attachment') {
         global $wpdb;
         $types = apply_filters('get_available_post_mime_types', null,
 $type);
         if ( ! is_array( $types ) ) {
                 $types = $wpdb->get_col($wpdb->prepare( "SELECT DISTINCT
 post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type ) );
         }
         return $types;
 }
 }}}

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


More information about the wp-trac mailing list