mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 02:11:08 -06:00
FIX: leaving around useless drafts after posting
This commit is contained in:
parent
d459cb95dc
commit
0fd1974838
@ -11,6 +11,7 @@ module Jobs
|
|||||||
Post.calculate_avg_time
|
Post.calculate_avg_time
|
||||||
Topic.calculate_avg_time
|
Topic.calculate_avg_time
|
||||||
ScoreCalculator.new.calculate
|
ScoreCalculator.new.calculate
|
||||||
|
Draft.cleanup!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,6 +34,15 @@ class Draft < ActiveRecord::Base
|
|||||||
find_by(user_id: user, draft_key: key)
|
find_by(user_id: user, draft_key: key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.cleanup!
|
||||||
|
exec_sql("DELETE FROM drafts where sequence < (
|
||||||
|
SELECT max(s.sequence) from draft_sequences s
|
||||||
|
WHERE s.draft_key = drafts.draft_key AND
|
||||||
|
s.user_id = drafts.user_id
|
||||||
|
)")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
@ -34,6 +34,24 @@ describe Draft do
|
|||||||
expect(Draft.get(@user, "test", 1)).to eq "hello"
|
expect(Draft.get(@user, "test", 1)).to eq "hello"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'can cleanup old' do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
key = Draft::NEW_TOPIC
|
||||||
|
seq = DraftSequence.next!(user, key)
|
||||||
|
|
||||||
|
Draft.set(user,key,seq,'draft')
|
||||||
|
DraftSequence.update_all('sequence = sequence + 1')
|
||||||
|
|
||||||
|
Draft.cleanup!
|
||||||
|
|
||||||
|
expect(Draft.count).to eq 0
|
||||||
|
Draft.set(Fabricate(:user), Draft::NEW_TOPIC, seq+1, 'draft')
|
||||||
|
|
||||||
|
Draft.cleanup!
|
||||||
|
|
||||||
|
expect(Draft.count).to eq 1
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'key expiry' do
|
context 'key expiry' do
|
||||||
it 'nukes new topic draft after a topic is created' do
|
it 'nukes new topic draft after a topic is created' do
|
||||||
|
Loading…
Reference in New Issue
Block a user