[wp-trac] [WordPress Trac] #61849: Improve performance and memory usage of wp_list_post_revisions() / wp_get_post_revisions()
WordPress Trac
noreply at wordpress.org
Fri Aug 9 10:47:41 UTC 2024
#61849: Improve performance and memory usage of wp_list_post_revisions() /
wp_get_post_revisions()
-------------------------+-----------------------------
Reporter: Toru | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Revisions | Version:
Severity: normal | Keywords:
Focuses: performance |
-------------------------+-----------------------------
I came across an issue where opening a Page in editor causing Fatal error
of `Allowed memory size of 268435456 bytes exhausted`. Trouble shooting
has lead me to find that there were over 4000 revisions (!) for this Page,
causing slow query and high memory usage. However, xhprofiling revealed
that higher memory usage was actually `update_meta_cache()`.
Putting aside why on earth there were over 4000 revisions...
After studying
[wp_post_revisions()](https://developer.wordpress.org/reference/functions/wp_list_post_revisions/),
I think it is unnecessary to do cache priming here. We can improve the
performance, and try to lower the possibility of exhausting memory.
`wp_list_post_revisions()` calls `wp_get_post_revisions()`, which calls
`get_children()`. WP_Post object returned by `wp_get_post_revisions()` is
substituted into `$revisions`, but post meta data are not needed to create
the list of revision links. Term data are also not needed.
So for [defaults args
here](https://github.com/WordPress/WordPress/blob/ddab80be2c0623cc8971a75180de40343f839f71
/wp-includes/revision.php#L667-L671)
{{{
$defaults = array(
'order' => 'DESC',
'orderby' => 'date ID',
'check_enabled' => true,
);
}}}
adding
{{{
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
}}}
should improve performance. On my local testing of above mentioned client
site, this haved the memory usage.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61849>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list