[wp-hackers] Disable/ Stop "auto-draft" posts
otto at ottodestruct.com
Tue Feb 28 19:11:22 UTC 2012
On Tue, Feb 28, 2012 at 10:50 AM, Jeff Lambert <jeff.lambert at jvhm.com> wrote:
> Appreciate the input on how drafts are cleaned up. 7 days seems like a long
> time for an auto save draft to live but it's good to know this and that
> cleaning does occur.
I don't know the reasoning behind the 7 day timer. Long enough to work
for all sane cases, not long enough to be annoying. It would break if
you opened a browser, went to post-new, then left the browser open and
didn't write anything for 7 days straight, then came back and tried to
> As for having to create the post to get the PostID, why not just generate a
> PostID, put it into the Post form and then use it when the author saves the
> Post, as opposed to actually saving the Post first? I'm assuming there is a
> downside somewhere but it would remove the need to have auto drafts (for
> this purpose), remove the need to clean and remove some DB/comm overhead.
Even if it did this, it would need a way to reserve that post ID
number and not hand it out to any other clients. Introducing a new
field somewhere to hold the latest post ID just moves the race
condition to a different place, it doesn't fix it. Creating the new
row and relying on the database to be consistent and durable is the
only way to do it.
If the next-valid-post-ID was stored somewhere else (say in an options
row), then getting it would involve a) selecting the row and b)
updating it to have the next number since we're taking this one. A
race condition occurs when two separate processes both select the row
simultaneously, before the update can happen.
Creating the new row and letting the DB decide on the post ID number
(it's an auto-increment field), then getting that row number, is the
only way to eliminate the condition. Even if two nearly-simultaneous
processes create new rows, the database itself will assign them post
ID's, ensuring that they cannot be the same.
More information about the wp-hackers