Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#51817 new enhancement

WP-Admin - Optimize main wpquery with 'fields' => 'ids' causes notice

Reported by: eumene's profile eumene Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5.3
Component: Administration Keywords: has-patch
Focuses: administration, performance Cc:


Hi all

I have a post_type (Woocommerce product) with a lot of data in the post contents. So, in wp-admin, WP requires a lot of memory to list them (sometimes I got an OUT-OF-MEMORY)

So, I tried to make a lighter query adding via hooks the query params
'fields' => 'ids'

It works! The query is more fast and WP does not require so many memory
but I got some annoying notices

In method _display_rows in WP_Posts_List_Table you have

foreach ( $posts as $a_post ) {
 $post_ids[] = $a_post->ID;

The method supposes that $posts will be an array of WP_Post object .
In my case it is an array of integer

Can you handle this scenario?

Change History (1)

This ticket was mentioned in PR #1182 on WordPress/wordpress-develop by eumene.

3 years ago

  • Keywords has-patch added

Data optimization in wp-admin / edit page / WP_Posts_List_Table data

In wp-admin/edit.php the main wp_query retrives all data and it requires a lot of memory

Then, WP_Posts_List_Table calls single_row method for each post in wp_query result set
In this method, the table calls
$post = get_post( $post );
to get al post data, already returned by the wp_query

So, I suggest to limit wp_query to post ID and parent ID for hierarchical post_type.
This solution:

  • optimize memory usage
  • speed up query time

This change adds one issue in WP_Posts_List_Table::_display_rows.
I added also a fix here to keep backward compatibility

Trac ticket:

Note: See TracTickets for help on using tickets.