Index: src/wp-admin/includes/template.php
===================================================================
--- src/wp-admin/includes/template.php	(revision 47290)
+++ src/wp-admin/includes/template.php	(working copy)
@@ -2179,6 +2179,8 @@
  * @return string Media states string.
  */
 function _media_states( $post ) {
+	static $header_images;
+
 	$media_states = array();
 	$stylesheet   = get_option( 'stylesheet' );
 
@@ -2186,7 +2188,9 @@
 		$meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true );
 
 		if ( is_random_header_image() ) {
-			$header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
+			if ( ! isset( $header_images ) ) {
+				$header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
+			}
 
 			if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
 				$media_states[] = __( 'Header Image' );
