Ticket #32264: 32264.6.patch
File 32264.6.patch, 3.7 KB (added by , 10 years ago) |
---|
-
src/wp-includes/media.php
2918 2918 } 2919 2919 } 2920 2920 2921 $has_audio = $wpdb->get_var( " 2922 SELECT ID 2923 FROM $wpdb->posts 2924 WHERE post_type = 'attachment' 2925 AND post_mime_type LIKE 'audio%' 2926 LIMIT 1 2927 " ); 2928 $has_video = $wpdb->get_var( " 2929 SELECT ID 2930 FROM $wpdb->posts 2931 WHERE post_type = 'attachment' 2932 AND post_mime_type LIKE 'video%' 2933 LIMIT 1 2934 " ); 2935 $months = $wpdb->get_results( $wpdb->prepare( " 2936 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 2937 FROM $wpdb->posts 2938 WHERE post_type = %s 2939 ORDER BY post_date DESC 2940 ", 'attachment' ) ); 2921 // Cache these expensive queries 2922 $has_audio = get_transient( 'has_audio' ); 2923 if ( false === $has_audio ) { 2924 $has_audio = $wpdb->get_var( " 2925 SELECT ID 2926 FROM $wpdb->posts 2927 WHERE post_type = 'attachment' 2928 AND post_mime_type LIKE 'audio%' 2929 LIMIT 1 2930 " ); 2931 $has_audio = $has_audio ? 1 : 0; 2932 set_transient( 'has_audio', $has_audio ); 2933 } 2934 $has_video = get_transient( 'has_video' ); 2935 if ( false === $has_video ) { 2936 $has_video = $wpdb->get_var( " 2937 SELECT ID 2938 FROM $wpdb->posts 2939 WHERE post_type = 'attachment' 2940 AND post_mime_type LIKE 'video%' 2941 LIMIT 1 2942 " ); 2943 $has_video = $has_video ? 1 : 0; 2944 set_transient( 'has_video', $has_video ); 2945 } 2946 $months = get_transient( 'media_months' ); 2947 if ( false === $months ) { 2948 $months = $wpdb->get_results( $wpdb->prepare( " 2949 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 2950 FROM $wpdb->posts 2951 WHERE post_type = %s 2952 ORDER BY post_date DESC 2953 ", 'attachment' ) ); 2954 set_transient( 'media_months', $months ); 2955 } 2956 2941 2957 foreach ( $months as $month_year ) { 2942 2958 $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year ); 2943 2959 } … … 2956 2972 ), 2957 2973 'defaultProps' => $props, 2958 2974 'attachmentCounts' => array( 2959 'audio' => ( $has_audio ) ? 1 : 0,2960 'video' => ( $has_video ) ? 1 : 02975 'audio' => intval( $has_audio ), 2976 'video' => intval( $has_video ) 2961 2977 ), 2962 2978 'embedExts' => $exts, 2963 2979 'embedMimes' => $ext_mimes, -
src/wp-includes/post.php
3477 3477 */ 3478 3478 do_action( 'edit_attachment', $post_ID ); 3479 3479 } else { 3480 // Delete persistent cache transients set in wp_enqueue_media 3481 $mime_type_prefix = substr( $postarr['post_mime_type'], 0, 5 ); 3482 if ( 'video' === $mime_type_prefix ) { 3483 delete_transient( 'has_video' ); 3484 } else if ( 'audio' === $mime_type_prefix ) { 3485 delete_transient( 'has_audio' ); 3486 } 3480 3487 3488 delete_transient( 'media_months' ); 3489 3481 3490 /** 3482 3491 * Fires once an attachment has been added. 3483 3492 * … … 4830 4839 $meta = wp_get_attachment_metadata( $post_id ); 4831 4840 $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); 4832 4841 $file = get_attached_file( $post_id ); 4842 $mime_type_prefix = substr( get_post_field( 'post_mime_type', $post_id ), 0, 5 ); 4833 4843 4834 4844 if ( is_multisite() ) 4835 4845 delete_transient( 'dirsize_cache' ); … … 4866 4876 /** This action is documented in wp-includes/post.php */ 4867 4877 do_action( 'deleted_post', $post_id ); 4868 4878 4879 // Delete persistent cache transients set in wp_enqueue_media 4880 if ( 'video' === $mime_type_prefix ) { 4881 delete_transient( 'has_video' ); 4882 } else if ( 'audio' === $mime_type_prefix ) { 4883 delete_transient( 'has_audio' ); 4884 } 4885 4886 delete_transient( 'media_months' ); 4887 4869 4888 $uploadpath = wp_upload_dir(); 4870 4889 4871 4890 if ( ! empty($meta['thumb']) ) {