WordPress.org

Make WordPress Core

Opened 11 months ago

Last modified 11 months ago

#45366 new defect (bug)

Optimize wp_get_post_revisions() call in wp_list_post_revisions()

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

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 11 months ago.
Patch from https://github.com/WordPress/WordPress/pull/386

Download all attachments as: .zip

Change History (4)

#1 follow-up: @greatislander
11 months 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
11 months 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
11 months 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().

Note: See TracTickets for help on using tickets.