WordPress.org

Make WordPress Core

Opened 2 months ago

#53607 new defect (bug)

Loading or saving a post with enough (large) revisions exhausts available memory

Reported by: mlbrgl Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.7.2
Component: Revisions Keywords:
Focuses: performance Cc:

Description

This is a follow-up to #34560.

What steps should be taken to consistently reproduce the problem?

  • create a post with enough (large) revisions (see "Steps to reproduce" from #34560).
  • Reduce WP_MAX_MEMORY_LIMIT so that it is enough to load one revision but not enough to load tens / hundreds of revisions (e.g. 128M)
  • save post -> Updating failed. The response is not a valid JSON response.
  • edit post -> **Fatal error**: Allowed memory size of 134217728 bytes exhausted

Does the problem occur even when you deactivate all plugins and use the default theme?

  • yes

Likely cause
It seems full post revisions (including post content) are still being loaded when editing a post. This is likely the cause of high memory consumption. To look into this:

  • on a standard WordPress installation, activate https://wordpress.org/plugins/debug-bar/ with
    <?php
    define( 'SAVEQUERIES', true );
    ?>
    
  • edit a post with revisions enabled
  • check the "Queries" tab of the debug bar (might need to turn off Gutenberg full screen mode to see it) and look for the query that loads the exhaustive list of full revisions (wp_posts.*):
SELECT wp_posts.* FROM wp_posts 
WHERE 1=1 AND wp_posts.post_parent = [[THE CURRENT POST ID]] 
AND wp_posts.post_type = 'revision' 
AND ((wp_posts.post_status = 'inherit')) 
ORDER BY wp_posts.post_date DESC, wp_posts.ID DESC

Attachments (3)

saving.png (24.7 KB) - added by mlbrgl 2 months ago.
Saving a post with enough large revisions
editing.png (39.2 KB) - added by mlbrgl 2 months ago.
Editing a post with enough large revisions
debug_query.png (608.7 KB) - added by mlbrgl 2 months ago.
The likely offending query exhausting available memory on posts with enough large revisions

Download all attachments as: .zip

Change History (3)

@mlbrgl
2 months ago

Saving a post with enough large revisions

@mlbrgl
2 months ago

Editing a post with enough large revisions

@mlbrgl
2 months ago

The likely offending query exhausting available memory on posts with enough large revisions

Note: See TracTickets for help on using tickets.