#56100 closed enhancement (fixed)
Call update_post_author_caches in WP_Posts_List_Table class
Reported by: | spacedmonkey | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Posts, Post Types | Keywords: | good-first-bug has-patch needs-dev-note |
Focuses: | administration, performance | Cc: |
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
@
2 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.
2 years ago
#4
Trac ticket: https://core.trac.wordpress.org/ticket/56100
#5
@
2 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
@
2 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
@
2 years ago
- Milestone changed from Future Release to 6.1
- Version set to 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.
Hi @spacedmonkey , I have added
update_post_author_caches()
function to thedisplay_rows
method inWP_Posts_List_Table
class and created a patch. Can you please review it and share your feedback?