Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#52999 closed enhancement (invalid)

Decrease the number of SQL queries in the pages list table

Reported by: chouby's profile Chouby Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch needs-testing
Focuses: administration, performance Cc:

Description

In the pages list table,
WP_Posts_List_Table::_display_rows_hierarchical() first calls get_pages(). Then we have the following call stack:
-> WP_Posts_List_Table::single_row() for all displayed pages
-> wp_check_post_lock()
-> get_post_meta()

The issue is that get_pages() doesn't prime the post meta cache. Thus all calls to get_post_meta() create a single SQL query, resulting in as many SQL queries as teh number of pages displayed in the list.

I propose to update the post cache before calling WP_Posts_List_Table::single_row() to decrease the number of SQL queries.

Attachments (1)

52999.diff (517 bytes) - added by Chouby 3 years ago.

Download all attachments as: .zip

Change History (8)

@Chouby
3 years ago

#1 @Chouby
3 years ago

  • Keywords has-patch added

#2 @audrasjb
3 years ago

  • Keywords needs-testing added
  • Milestone changed from Awaiting Review to 5.8
  • Type changed from defect (bug) to enhancement

Hi @Chouby,

Thanks, it looks like a great enhancement.
While I'm planning some performance tests on my side, let's change the ticket type to enhancement and move it for 5.8 consideration.

#3 @audrasjb
3 years ago

I ran some quick tests using query monitor and here are the results:

Before patch:
- Page Generation Time: 0,9868 | 3,3% of 30s limit
- Peak Memory Usage: 87 072 kB | 16,6% of 524 288 kB limit
- Database Query Time: 0,0255
- Database Queries: Total: 85
- Object Cache: 94,4% hit rate (4 506 hits, 266 misses)
- - - -
After patch: 
- Page Generation Time: 0,9690 | 3,2% of 30s limit
- Peak Memory Usage: 87 065 kB | 16,6% of 524 288 kB limit
- Database Query Time: 0,0217
- Database Queries: Total: 84
- Object Cache: 94,5% hit rate (4 515 hits, 264 misses)

That was tested on a small website. Would be nice to get some tests on a bigger one.

#4 @SergeyBiryukov
3 years ago

  • Component changed from Administration to Posts, Post Types
  • Focuses administration added

#5 @Chouby
3 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Sorry for the noise. In fact the call to _prime_post_caches() does in fine calls update_postmeta_cache(). Not sure why this did not work in my install. I am not able to reproduce anymore.

#6 @audrasjb
3 years ago

  • Milestone 5.8 deleted

#7 @audrasjb
3 years ago

Weird. It looked like it was reproductible on my side as well yesterday. Nevermind 🤷‍♂️

Note: See TracTickets for help on using tickets.