#56100 closed enhancement (fixed)
Call update_post_author_caches in WP_Posts_List_Table class
| Reported by: | spacedmonkey | Owned by: | spacedmonkey |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.1 |
| Component: | Posts, Post Types | Version: | 3.0 |
| Severity: | normal | Keywords: | good-first-bug has-patch needs-dev-note |
| Cc: | Focuses: | administration, performance |
Description
In 6.1, update_post_author_caches was introduced. Call this function in WP_Posts_List_Table class, to prime user caches in one request and save database queries.
Attachments (3)
Change History (13)
#2
@
4 years ago
public function display_rows( $posts = array(), $level = 0 ) { global $wp_query, $per_page; if ( empty( $posts ) ) { $posts = $wp_query->posts; update_post_author_caches( $posts ); }
@thakkarhardik I was thinking about something like this.
This ticket was mentioned in PR #2942 on WordPress/wordpress-develop by spacedmonkey.
4 years ago
#4
Trac ticket: https://core.trac.wordpress.org/ticket/56100
#5
@
4 years ago
@thakkarhardik I did some testing and notice some notice errors. It seems in page list views, that only id and parent is loaded.
I have push my own patch up, see what you think.
#6
@
4 years ago
What about adding this to update_post_caches()? update_post_caches.diff is a proof of concept.
Updates post, term, and metadata caches for a list of post objects.
Authors are really the only thing not being primed for posts (except comments, but that's a separate thing that is not always required). It's reasonable to consider author information is a required part of a post.
I'm not aware if there is a historical reason why this was left out previously, though.
#7
@
4 years ago
- Milestone Future Release → 6.1
- Version → 3.0
For context [53482] and #55716.
Priming users can expensive and should be avoided if possible. In [53482] users are only primed in the loop. So for the most part, most uses of WP_Query will already be covered. There are only a couple of uses in core like this do not use the loop and get posts.
Also WP_Posts_List_Table does something odd around pages, see this. This loads all pages. This change ensues that only displayed posts users are primed.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi @spacedmonkey , I have added
update_post_author_caches()function to thedisplay_rowsmethod inWP_Posts_List_Tableclass and created a patch. Can you please review it and share your feedback?