Make WordPress Core

Opened 8 years ago

Closed 2 years ago

#45366 closed defect (bug) (duplicate)

Optimize wp_get_post_revisions() call in wp_list_post_revisions()

Reported by: greatislander Owned by:
Priority: normal Milestone:
Component: Revisions Version: 4.9.8
Severity: normal Keywords: has-patch
Cc: Focuses: performance

Description

Currently, wp_list_post_revisions() calls wp_get_post_revisions() with the current post's ID as the only argument. This fetches full post objects for each revision. When the current post is very large and has an extensive revision history, this can cause out-of-memory issues (this has been observed when loading a post with ~43,000 words and 158 revisions). While limiting the number of revisions can address this issue, as far as I can tell there is no reason to load full post objects for all revisions, as all of the subsequently called functions in wp_list_post_revisions() only require a revision ID. Calling wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) ) significantly improves the performance of this function under such circumstances.

Attachments (1)

45366.diff​ (690 bytes ) - added by greatislander 8 years ago.
Patch from ​https://github.com/WordPress/WordPress/pull/386

Download all attachments as: .zip

Change History (7)

#1 follow-up: @greatislander
8 years ago

  • Keywords has-patch added; needs-patch removed

Digging deeper, it looks like wp_post_revision_title_expanded() will fetch full post objects if passed an ID, even though it only needs post_type, post_author and post_modified. So this can probably be optimized as well. I'll open as a second issue.

#2 in reply to: ↑ 1 @birgire
8 years ago

Replying to greatislander:

Digging deeper, it looks like wp_post_revision_title_expanded() will fetch full post objects if passed an ID, even though it only needs post_type, post_author and post_modified. So this can probably be optimized as well. I'll open as a second issue.

If I understand correctly you see performance gain with 45366.diff​ even though wp_post_revision_title_expanded() is fetching full post objects?

Somewhat related is #44321 with similar improvements made within the REST API for the revision count:

https://core.trac.wordpress.org/ticket/44321#comment:5

#3 @greatislander
8 years ago

@birgire My patch is premature and needs more testing, and unfortunately I don't think it fully addresses the performance issues given what's going on with wp_post_revision_title_expanded().

#4 @pbearne
2 years ago

We have a ticket created for wp_post_revision_title_expanded()

Does this still need to patched?

Paul

This ticket was mentioned in ​Slack in #core-performance by mukeshpanchal27. ​View the logs.


2 years ago

#6 @adamsilverstein
2 years ago

  • Milestone Awaiting Review
  • Resolution → duplicate
  • Status new → closed

Closing this as a duplicate of #61849 (although this ticket is older, the description and PR on the new ticket are more complete so I'm closing this one).

Note: See TracTickets for help on using tickets.