Make WordPress Core


Ignore:
Timestamp:
05/06/2014 03:21:56 AM (12 years ago)
Author:
nacin
Message:

Avoid an expensive attachment counting query on the post editing screen.

Merges [28191], [28194] to the 3.9 branch.

props johnbillion.
fixes #27985.

Location:
branches/3.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.9

  • branches/3.9/src/wp-includes/media.php

    r28233 r28261  
    26552655                return;
    26562656
    2657         global $content_width;
     2657        global $content_width, $wpdb;
    26582658
    26592659        $defaults = array(
     
    26942694        }
    26952695
    2696         $audio = $video = 0;
    2697         $counts = (array) wp_count_attachments();
    2698         foreach ( $counts as $mime => $total ) {
    2699                 if ( 0 === strpos( $mime, 'audio/' ) ) {
    2700                         $audio += (int) $total;
    2701                 } elseif ( 0 === strpos( $mime, 'video/' ) ) {
    2702                         $video += (int) $total;
    2703                 }
    2704         }
     2696        $has_audio = $wpdb->get_var( "
     2697                SELECT ID
     2698                FROM $wpdb->posts
     2699                WHERE post_type = 'attachment'
     2700                AND post_mime_type LIKE 'audio%'
     2701                LIMIT 1
     2702        " );
     2703        $has_video = $wpdb->get_var( "
     2704                SELECT ID
     2705                FROM $wpdb->posts
     2706                WHERE post_type = 'attachment'
     2707                AND post_mime_type LIKE 'video%'
     2708                LIMIT 1
     2709        " );
    27052710
    27062711        $settings = array(
     
    27182723                'defaultProps' => $props,
    27192724                'attachmentCounts' => array(
    2720                         'audio' => $audio,
    2721                         'video' => $video
     2725                        'audio' => (int) $has_audio,
     2726                        'video' => (int) $has_video,
    27222727                ),
    27232728                'embedExts'    => $exts,
Note: See TracChangeset for help on using the changeset viewer.