[wp-trac] [WordPress Trac] #51817: WP-Admin - Optimize main wpquery with 'fields' => 'ids' causes notice
WordPress Trac
noreply at wordpress.org
Tue Jun 10 16:09:55 UTC 2025
#51817: WP-Admin - Optimize main wpquery with 'fields' => 'ids' causes notice
-------------------------------------+-------------------------------------
Reporter: eumene | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version: 5.5.3
Severity: normal | Resolution:
Keywords: has-patch reporter- | Focuses: administration,
feedback | performance
-------------------------------------+-------------------------------------
Comment (by eumene):
Well...
This is the current _display_rows methdo
{{{#!php
<?php
private function _display_rows( $posts, $level = 0 ) {
$post_type = $this->screen->post_type;
// Create array of post IDs.
$post_ids = array();
foreach ( $posts as $a_post ) {
$post_ids[] = $a_post->ID;
}
if ( post_type_supports( $post_type, 'comments' ) ) {
$this->comment_pending_count =
get_pending_comments_num( $post_ids );
}
update_post_author_caches( $posts );
foreach ( $posts as $post ) {
$this->single_row( $post, $level );
}
}
}}}
foreach post retrived it will call single_row method, which is
{{{#!php
<?php
/**
* @global WP_Post $post Global post object.
*
* @param int|WP_Post $post
* @param int $level
*/
public function single_row( $post, $level = 0 ) {
$global_post = get_post();
$post = get_post( $post );
$this->current_level = $level;
$GLOBALS['post'] = $post;
setup_postdata( $post );
$classes = 'iedit author-' . ( get_current_user_id() ===
(int) $post->post_author ? 'self' : 'other' );
$lock_holder = wp_check_post_lock( $post->ID );
if ( $lock_holder ) {
$classes .= ' wp-locked';
}
if ( $post->post_parent ) {
$count = count( get_post_ancestors( $post->ID )
);
$classes .= ' level-' . $count;
} else {
$classes .= ' level-0';
}
?>
<tr id="post-<?php echo $post->ID; ?>" class="<?php echo
implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
<?php $this->single_row_columns( $post ); ?>
</tr>
<?php
$GLOBALS['post'] = $global_post;
}
}}}
it contains the line
{{{
$post = get_post( $post );
}}}
it means that for each post (it could be just the ID) the full object will
be retrived to fill the table.
The point is that I do not want load all post data twice:
- first time in the WP_Posts_List_Table main query (if I have huge
post_content, this query will be able to create a memory issue)
- second time for each single_row call
I hope it could be more clear
Diego
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51817#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list