Ticket #32264: 32264.5.patch
File 32264.5.patch, 3.6 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 if ( false === ( $has_audio = get_transient( 'has_audio' ) ) ) { 2923 $has_audio = $wpdb->get_var( " 2924 SELECT ID 2925 FROM $wpdb->posts 2926 WHERE post_type = 'attachment' 2927 AND post_mime_type LIKE 'audio%' 2928 LIMIT 1 2929 " ); 2930 $has_audio = $has_audio ? 1 : 0; 2931 set_transient( 'has_audio', $has_audio ); 2932 } 2933 if ( false === ( $has_video = get_transient( 'has_video' ) ) ) { 2934 $has_video = $wpdb->get_var( " 2935 SELECT ID 2936 FROM $wpdb->posts 2937 WHERE post_type = 'attachment' 2938 AND post_mime_type LIKE 'video%' 2939 LIMIT 1 2940 " ); 2941 $has_video = $has_video ? 1 : 0; 2942 set_transient( 'has_video', $has_video ); 2943 } 2944 if ( false === ( $months = get_transient( 'media_months' ) ) ) { 2945 $months = $wpdb->get_results( $wpdb->prepare( " 2946 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 2947 FROM $wpdb->posts 2948 WHERE post_type = %s 2949 ORDER BY post_date DESC 2950 ", 'attachment' ) ); 2951 set_transient( 'media_months', $months ); 2952 } 2953 2941 2954 foreach ( $months as $month_year ) { 2942 2955 $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year ); 2943 2956 } … … 2956 2969 ), 2957 2970 'defaultProps' => $props, 2958 2971 'attachmentCounts' => array( 2959 'audio' => ( $has_audio ) ? 1 : 0,2960 'video' => ( $has_video ) ? 1 : 02972 'audio' => intval( $has_audio ), 2973 'video' => intval( $has_video ) 2961 2974 ), 2962 2975 'embedExts' => $exts, 2963 2976 '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']) ) {