Opened 5 years ago

Last modified 2 weeks ago

#7392 reopened defect (bug)

Don't create new autosave revision if nothing has changed yet

Reported by: Otto42 Owned by: westi
Priority: normal Milestone: 3.6
Component: Autosave Version: 2.6
Severity: minor Keywords: has-patch needs-testing 3.6-early autosave-redo
Cc: AmbushCommander, kurtpayne, adamsilverstein@…, dh-shredder

Description

I noticed that simply loading and saving a post creates a new revision. This seems rather dumb to me. Could we not load the post up, compare it with the revision, and not create a whole new revision if nothing changed (ignoring post save time, of course)?

Discuss.

Attachments (8)

7392.diff (2.3 KB) - added by solarissmoke 2 years ago.
7392-2.diff (2.6 KB) - added by adamsilverstein 4 months ago.
7392-3.diff (2.5 KB) - added by adamsilverstein 3 months ago.
removed error_log
revisions.php (1.7 KB) - added by adamsilverstein 3 months ago.
corrected php doc, removed empty setup teardown
dont-save-autosave.2.diff (1.3 KB) - added by adamsilverstein 2 months ago.
adds check in wp_create_post_autosave for duplicate content
dont-save-autosave.diff (1.1 KB) - added by adamsilverstein 2 months ago.
adds check in wp_create_post_autosave for duplicate content
7392-autosave.patch (1.5 KB) - added by azaozz 2 months ago.
7392.2.diff (1.6 KB) - added by adamsilverstein 2 weeks ago.
check for duplicate data before autosaving in wp_create_post_autosave

Download all attachments as: .zip

Change History (37)

  • Summary changed from Don't create new revision if nothing changed to Don't create new autosave revision if nothing has changed yet

Additional: I worded that badly.

What I mean is that when I load a post up and wait for the autosave, I get the autosave revision there, and future loads of that post tell me that there's a newer autosave, even though nothing has changed with the post.

Can we disable autosave until something actually changes in the post?

  • Milestone changed from 2.9 to 2.8
  • Keywords needs-patch added
  • Milestone changed from 2.8 to Future Release
  • Component changed from General to Autosave
  • Owner anonymous deleted
  • Severity changed from normal to minor
  • Type changed from enhancement to defect (bug)

+1 to this. I'm guessing it would be fairly easy to fix, though I haven't investigated.

  • Cc AmbushCommander added
  • Keywords has-patch needs-testing added; needs-patch removed

This patch prevents revisions being created if the content hasn't changed. I think it should resolve #9843 as well.

  • Cc kurtpayne added
  • Keywords 3.6-early added

Confirmed original issue and tested 7392.diff. Looks good.

  • Keywords revisions-3.6 autosave-redo added

Maybe a candidate for investigation and resolution during the autosave/revision work in 3.6.

http://make.wordpress.org/core/2013/01/19/autosave-and-post-locking/

  • Keywords revisions-3.6 removed
  • Milestone changed from Future Release to 3.6
  • Component changed from Autosave to Revisions

comment:13 in reply to: ↑ 12   westi4 months ago

  • Component changed from Revisions to Autosave

Replying to SergeyBiryukov:

I left this in Autosave as it is an Autosave issue not a revisions issue.

comment:14 follow-up: ↓ 15   azaozz4 months ago

This happens only when the Visual editor is default (is shown first). Caused by running the post_content through wpautop before outputting it in the textarea (TinyMCE needs the <p>), so the first autosaveLast (used to determine if something has changed) gets post_content with <p> and is later compared to post_content without <p>.

There are better ways to do that, should be fixed with the autosave updates in 3.6.

comment:15 in reply to: ↑ 14   adamsilverstein4 months ago

Replying to azaozz:

This happens only when the Visual editor is default (is shown first). Caused by running the post_content through wpautop before outputting it in the textarea (TinyMCE needs the <p>), so the first autosaveLast (used to determine if something has changed) gets post_content with <p> and is later compared to post_content without <p>.

There are better ways to do that, should be fixed with the autosave updates in 3.6.

i've noticed this doesn't get fired on new posts if i create a post and publish it with just a title without entering any content.

in addition to the extra autosave, this winds up creating an extra revision, so creating a post with title and content starts out with two revisions, the 1st one is title only, the 2nd has title and content. thats confusing to users - see #9843. the current patch seems to do too much by checking for duplication, can we just check for the initial state you mention and skip the first and only the first autosave?

going to test the current patch anyway.

Version 1, edited 4 months ago by adamsilverstein (previous) (next) (diff)

the current patch works as advertised, the post is not updated if the content is unchanged.

posting corrected diff so patch works agains current for testing.

investigating double initial revisions (related - #9843, #16215 ) next.

This is also something we noticed while doing #22687.

  • Cc adamsilverstein@… added
  • Cc dh-shredder added
  • Owner set to westi
  • Status changed from new to assigned

Assigning to westi — can you take another look?

removed error_log

corrected php doc, removed empty setup teardown

In 1211/tests:

Revisions: When we are trying to save a new revision we shouldn't save one if the previous version was the same.

See #7392 and #9843 props adamsilverstein

  • Resolution set to fixed
  • Status changed from assigned to closed

In 23414:

Revisions: Before saving a new post revision make sure that something has changed in the fields that we are revisioning.

Fixes: #7392 and #9843 props adamsilverstein.

In 1214/tests:

Revisions: Add a new test for a force save filter in wp_save_post_revision

Also Update the tests to have correct ordering, be less complex and use things like assertCount.
See #7392 and #9843

In 23415:

Revisions: Allow a plugin to force us to skip the don't save this revision because it hasn't changed code if it knows better.

See #7392 and #9843. Also cleans up the whitespace.

adds check in wp_create_post_autosave for duplicate content

adds check in wp_create_post_autosave for duplicate content

dont-save-autosave.diff won't work as expected (and has a copy/paste typo, $new_data is not defined in wp_create_post_autosave()).

It only checks whether the autosave is the same as the current post when a previous autosave exists. To catch the first autosave, perhaps we can move the test for changed fields from wp_save_post_revision() to _wp_put_post_revision(). We will still need the same test in wp_create_post_autosave() for the cases when an autosave is updated.

azaozz2 months ago

comment:26 follow-up: ↓ 27   azaozz2 months ago

Alternatively something like 7392-autosave.patch​ should work.

comment:27 in reply to: ↑ 26   adamsilverstein2 months ago

Replying to azaozz:

Alternatively something like 7392-autosave.patch​ should work.

thanks, that looks good. do we still need the check in _wp_put_post_revision as well? will try testing this patch.

  • Resolution fixed deleted
  • Status changed from closed to reopened

Re-opening due to remaining patches.

check for duplicate data before autosaving in wp_create_post_autosave

in 7392.2.diff​:

  • add duplicate content check in wp_create_post_autosave, refreshed from 7392-autosave.patch
  • note that if "revisioned fields" (by default: title, content, excerpt) are unchanged, autosaves will not fire, even if you change revisioned post_meta such as post format. (also true of regular update revisions)
Note: See TracTickets for help on using tickets.