[wp-trac] [WordPress Trac] #62057: Addressing Autosave Memory Issues

WordPress Trac noreply at wordpress.org
Tue Sep 17 20:50:20 UTC 2024


#62057: Addressing Autosave Memory Issues
--------------------------+------------------------------
 Reporter:  whyisjake     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Autosave      |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  rest-api
--------------------------+------------------------------

Comment (by whyisjake):

 == Sample Filter

 {{{#!php
 <?php

 // Removes the autosaves route from editor
 // It can OOM PHP when autosave parallelism (count per-post) is massive
 // this sidesteps it and compels JS to fetch it from the /autosaves/ route
 directly

 function remove_autosaves_from_preload_paths( $preload_paths,
 $block_editor_context ) {
  // Loop through preload paths and remove any containing '/autosaves'
  foreach ( $preload_paths as $key => $path ) {
      // Handle paths that are arrays (like the 'OPTIONS' ones)
      if ( is_array( $path ) ) {
          if ( strpos( $path[0], '/autosaves' ) !== false ) {
              unset( $preload_paths[$key] );
          }
      }
      // Handle string paths
      elseif ( strpos( $path, '/autosaves' ) !== false ) {
          unset( $preload_paths[$key] );
      }
  }

  return $preload_paths;
 }
 add_filter( 'block_editor_rest_api_preload_paths',
 'remove_autosaves_from_preload_paths', 10, 2 );

 }}}


 == How to verify:
 1. make a post, save it, make an edit and wait on that page with it open
 (so an autosave happens)
 2. open same post in another tab, get the yellow “there is an autosave”
 warning
 3. reload with brwoser devtools > network open and filter for “autosave”
 4. with this filter active, you’ll see that gutenberg fetches the autosave
 data from the rest route
 5. you can toggle the filter too: with the filter inactive, no rest
 request for autosaves is made, because it’s preloaded

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62057#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list