Make WordPress Core

Opened 2 years ago

Closed 21 months ago

Last modified 21 months ago

#56100 closed enhancement (fixed)

Call update_post_author_caches in WP_Posts_List_Table class

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile 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:


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)

56100.patch (565 bytes) - added by thakkarhardik 2 years ago.
56100.2.patch (552 bytes) - added by thakkarhardik 2 years ago.
Updated Patch
update_post_caches.diff (1.0 KB) - added by desrosj 23 months ago.

Download all attachments as: .zip

Change History (13)

2 years ago

#1 @thakkarhardik
2 years ago

  • Keywords has-patch added; needs-patch removed

Hi @spacedmonkey , I have added update_post_author_caches() function to the display_rows method in WP_Posts_List_Table class and created a patch. Can you please review it and share your feedback?

#2 @spacedmonkey
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.

2 years ago

Updated Patch

#3 @thakkarhardik
2 years ago

Thanks @spacedmonkey . Your suggestion seems better. I've updated the patch.

#5 @spacedmonkey
23 months 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 @desrosj
23 months 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 @spacedmonkey
23 months 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.

#8 @spacedmonkey
23 months ago

  • Owner set to spacedmonkey
  • Status changed from new to assigned

#9 @spacedmonkey
21 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 54099:

Posts, Post Types: Call update_post_author_caches function in WP_Posts_List_Table class.

Call the update_post_author_caches function in the WP_Posts_List_Table class to prime post author caches in a single database request.

Props spacedmonkey, thakkarhardik, desrosj.
Fixes #56100.

#10 @desrosj
21 months ago

  • Keywords needs-dev-note added

There are a lot of caching related changes in 6.1 and a dev note should be written collecting them all. Marking this for inclusion.

Note: See TracTickets for help on using tickets.