Many drafts of published posts exist in the database

(Allen - Watchman Monitoring) #1

Hi all

I was looking for a post by a user, and found that there are many (568 in our forum of ~1200 posts) drafts of posts which have been published.

Is this intentional? Will they be trimmed later?

(Jeff Atwood) #2

Good find! @sam do we have a cleanup process for very old drafts? Can you check meta to see how many there are?

(Sam Saffron) #4

misread the title here published should be cleared from drafts, will have a look

(Jeff Atwood) #5

Regardless, very old drafts should be cleaned up as well. Same scenario in my mind.

(Jeff Atwood) #6

@techapj can you add this to your list? May require downloading a Discourse database (perhaps Meta) and checking it for lots of orphan drafts.

(Arpit Jalan) #7

Okay, I just pushed a new job to clean up old drafts (older than 90 days by default) weekly:

(Allen - Watchman Monitoring) #8

Most of the drafts I saw were for topics which were later create.

Does this account for when the draft has been published? or if someone has an unpublished draft for a long time, will it end up getting purged?

(Jeff Atwood) #9

A user can only have one new topic draft at any given time, so “most” of those drafts must have been for single users.

I don’t see any reason to keep drafts around forever @sam, on discourse.codinghorror alone there are over 1,200 “outstanding” “drafts”.

Provided you move this to a single site setting of days, @techAPJ, I will pull this in personally if need be.

(Sam Saffron) #10

It’s not adding any value , except for making people feel warm and fuzzy inside cause they just saved one whole megabyte of storage.

Also that pr is not checking modified date which it should instead of create date. And this is not even diagnosing the issue reported, jtst sweeping it under table.

(Jeff Atwood) #11

Fine, @techapj can change it to look at modification date… we do plenty of cleanup, and did you read the original stats?

We can deal with the rest of it later, I honestly don’t care why there are so many orphan drafts, but they need to go. It’s like 10 lines of code to clean them up, if you want them forever, set days to 99999.

(Allen - Watchman Monitoring) #12

my point isn’t that i want to keep them around… I’m suggesting that once a reply has been posted, its related draft should be cleaned up.

If post is never posted, then the draft would just be there.

(Kane York) #13

Hmm, I don’t think that PostCreator has any code to delete drafts. Maybe that’s the problem - it should get passed a draft_key parameter that it deletes all the drafts for in the transaction.

(Sam Saffron) #14

I’m mainly objecting here to the nuclear fix vs a surgical fix, let me clean up all the crap and then see how big the problem is

(Jeff Atwood) #15

I don’t agree, 10 lines of code to discard drafts that are 300+ days old is necessary in any case. These two things can work together.

(Allen - Watchman Monitoring) #16

Time has little to do with the issue at hand IMO.

1-start a draft
2-post the topic
3-expect the draft to be gone.


1-start a draft
2-don’t finish posting
3-expect it to be there when you get back.

(Jeff Atwood) #17

Can you give repro steps for that please? Can you repro on e.g. list a set of steps that results in me posting and then seeing a draft of the thing I just posted, somehow, in my web browser.

Regardless, I strenously object to 300+ day old drafts. They need to be burned with :fire: – and it’s also a nice fix for whatever the other problem is, until we have repro steps… or more time to deal with it…

(Allen - Watchman Monitoring) #18

Because the topic is about trash in the DB, I can’t repro on try (or any other hosted discourse) as issue only exists in at the database level. The UI is just fine.

I agree that people shouldn’t readily expect a 300 day old draft to still be there. I’m just saying it’s not time-related.

(Kane York) #19

I have repro in a video, will have to check it over & encode

(Sam Saffron) #20

I fixed this on the plane will push a fix soon

We never deleted drafts

(Sam Saffron) #21

Fixed per:


We have a spot for weekly cleanup if we want to extend it