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 | |