WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 4 months ago

#51817 new enhancement

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

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

Description

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.


4 months ago

  • Keywords has-patch added

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

https://core.trac.wordpress.org/ticket/51817

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: https://core.trac.wordpress.org/ticket/51817

Note: See TracTickets for help on using tickets.