Make WordPress Core

Opened 5 years ago

Last modified 8 months ago

#53607 new defect (bug)

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

Reported by: mlbrgl's profile 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 5 years ago.
Saving a post with enough large revisions
editing.png (39.2 KB) - added by mlbrgl 5 years ago.
Editing a post with enough large revisions
debug_query.png (608.7 KB) - added by mlbrgl 5 years ago.
The likely offending query exhausting available memory on posts with enough large revisions

Download all attachments as: .zip

Change History (5)

@mlbrgl
5 years ago

Saving a post with enough large revisions

@mlbrgl
5 years ago

Editing a post with enough large revisions

@mlbrgl
5 years ago

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

#1 @flixos90
8 months ago

Thank you for the report @mlbrgl, and welcome to Trac. Apologies for this only being reviewed now after all this time.

Is this still a problem you're facing? Would it be an option to limit the number of revisions that are saved for a post?

Overall, this seems like a valid issue, but I'm unsure how it could be addressed other than having adequate memory limit. Do you have any suggestions?

cc @spacedmonkey @adamsilverstein for visibility

#2 @mlbrgl
8 months ago

Hi @flixos90, thanks for getting back to me, and no worries about timing :)

IIRC, we did end up limiting the number of saved revisions at the time, but moved off of WP since.

I'm fine with closing if this doesn't need to be tracked anymore.

Note: See TracTickets for help on using tickets.