[wp-trac] [WordPress Trac] #49532: Clicking "preview" multiple times on a post causes an identical autosave revision to be created and destroyed repeatedly

WordPress Trac noreply at wordpress.org
Fri Feb 28 13:08:07 UTC 2020


#49532: Clicking "preview" multiple times on a post causes an identical autosave
revision to be created and destroyed repeatedly
--------------------------+------------------------------------
 Reporter:  inwerpsel     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Revisions     |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  rest-api, performance
--------------------------+------------------------------------

Comment (by inwerpsel):

 Looks like this issue occurs in more cases than I previously found. The
 autosave record is also temporarily cleaned up when loading the block
 editor in post.php. The autosave is looked up there to see if it is newer
 than the latest edit of the post, if it's not then it's deleted there.

 https://github.com/WordPress/WordPress/blob/master/wp-admin/edit-form-
 blocks.php#L323

 Will anything break if the autosave isn't deleted in both cases? I would
 guess not at first glance, but maybe I'm missing something. I forced this
 locally by adding a filter:
 {{{#!php
 <?php
 // ...
         add_filter('pre_delete_post', [$this, 'do_not_delete_autosave'],
 1, 3);
 // ...
         public function do_not_delete_autosave( $something = null, $post =
 null, $force_delete = null ): ?bool {
                 if ( preg_match( '/autosave-v\d+$/', $post->post_name ) )
 {
                         return false;
                 }

                 return null;
         }

 }}}
 This doesn't seem to break anything. The only downside I see is that for
 each different author the autosave will be preserved indefinitely. However
 this is already the case for some of the autosaves, if no request that
 deletes the autosave is done after it has been created. Also that still
 seems preferable compared to deleting and creating new records many times
 over.

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


More information about the wp-trac mailing list