Media: Cache parent posts in query-attachments AJAX endpoint.

Prime the parent post objects `wp_ajax_query_attachments()` to reduce the number of database queries in the query-attachments admin-ajax endpoint.

Props albatross10.
Fixes #56037.



git-svn-id: https://develop.svn.wordpress.org/trunk@53885 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2022-08-12 00:15:20 +00:00
parent 299c8485c0
commit c2e2e55b0d

View File

@ -3038,6 +3038,7 @@ function wp_ajax_query_attachments() {
*/
$query = apply_filters( 'ajax_query_attachments_args', $query );
$attachments_query = new WP_Query( $query );
update_post_parent_caches( $attachments_query->posts );
$posts = array_map( 'wp_prepare_attachment_for_js', $attachments_query->posts );
$posts = array_filter( $posts );