Opened 6 years ago
Closed 6 months ago
#45366 closed defect (bug) (duplicate)
Optimize wp_get_post_revisions() call in wp_list_post_revisions()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9.8 |
Component: | Revisions | Keywords: | has-patch |
Focuses: | performance | Cc: |
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)
Change History (7)
#1
follow-up:
↓ 2
@
6 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
@
6 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 needspost_type
,post_author
andpost_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:
#3
@
6 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
@
8 months ago
We have a ticket created for wp_post_revision_title_expanded()
Does this still need to patched?
Paul
Patch from https://github.com/WordPress/WordPress/pull/386