Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#56272 closed enhancement (fixed)

REST API: Prime post caches in comments in endpoint.

Reported by: spacedmonkey's profile spacedmonkey Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.1 Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: has-patch commit has-dev-note
Focuses: performance Cc:

Description

In the WP_REST_Comments_Controller class, there are multiple calls to the comment's post, why calling get_post like this,

   $post = get_post( (int) $comment->comment_post_ID );

Post caches should be primed using the update_comment_post_cache param.

Attachments (2)

Screenshot 2022-07-22 at 18.52.03.png (1.3 MB) - added by spacedmonkey 2 years ago.
Before
Screenshot 2022-07-22 at 18.59.01.png (1.3 MB) - added by spacedmonkey 2 years ago.
After

Change History (13)

This ticket was mentioned in PR #3014 on WordPress/wordpress-develop by spacedmonkey.


2 years ago
#1

  • Keywords has-patch added

TimothyBJacobs commented on PR #3014:


2 years ago
#2

Aside from the CS issue, looks good to merge to me.

#3 @spacedmonkey
2 years ago

  • Keywords commit added
  • Owner set to spacedmonkey
  • Status changed from new to assigned

#4 @peterwilsoncc
2 years ago

  • Milestone changed from Future Release to 6.1
  • Owner changed from spacedmonkey to peterwilsoncc

I think this can go in 6.1.

I've self assigned it for commit as Jonny is AFK for the next few weeks.

#5 @peterwilsoncc
2 years ago

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

In 53772:

REST API: Prime post caches in comments endpoint.

Prevent each call to get_post() triggering a seperate database query by priming the cache of each comment's post in
the REST API's comments endpoint.

Props spacedmonkey, timothyblynjacobs.
Fixes #56272.

peterwilsoncc commented on PR #3014:


2 years ago
#6

Committed in https://core.trac.wordpress.org/changeset/53772 (c1cf07e4e30cf0a2fde3f2be0a6983025b3d2062)

#7 @desrosj
2 years ago

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

#8 @desrosj
2 years ago

  • Keywords needs-dev-note added

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


2 years ago

#10 @spacedmonkey
2 years ago

Early draft of a dev note can be found here.

Note: See TracTickets for help on using tickets.