FIX: Update draft count when sequence is increased (#13940)
* FIX: Update draft count when sequence is increased Sometimes users ended up having a draft count higher than the actual number of drafts. * FIX: Do not update draft count twice The call to DraftSequence.next! above already does it.
This commit is contained in:
parent
e2af2a2219
commit
d9843d757a
|
@ -23,6 +23,8 @@ class DraftSequence < ActiveRecord::Base
|
|||
|
||||
DB.exec("DELETE FROM drafts WHERE user_id = :user_id AND draft_key = :draft_key AND sequence < :sequence", draft_key: key, user_id: user_id, sequence: sequence)
|
||||
|
||||
UserStat.update_draft_count(user_id)
|
||||
|
||||
sequence
|
||||
end
|
||||
|
||||
|
|
|
@ -229,7 +229,6 @@ class PostCreator
|
|||
@post.topic.reload
|
||||
|
||||
publish
|
||||
UserStat.update_draft_count(@user.id)
|
||||
|
||||
track_latest_on_category
|
||||
enqueue_jobs unless @opts[:skip_jobs]
|
||||
|
|
|
@ -167,6 +167,7 @@ describe PostCreator do
|
|||
"/topic/#{created_post.topic_id}",
|
||||
"/topic/#{created_post.topic_id}",
|
||||
"/user",
|
||||
"/user",
|
||||
"/user"
|
||||
].sort
|
||||
)
|
||||
|
@ -196,7 +197,10 @@ describe PostCreator do
|
|||
user_action = messages.find { |m| m.channel == "/u/#{p.user.username}" }
|
||||
expect(user_action).not_to eq(nil)
|
||||
|
||||
expect(messages.filter { |m| m.channel != "/distributed_hash" }.length).to eq(6)
|
||||
draft_count = messages.find { |m| m.channel == "/user" }
|
||||
expect(draft_count).not_to eq(nil)
|
||||
|
||||
expect(messages.filter { |m| m.channel != "/distributed_hash" }.length).to eq(7)
|
||||
end
|
||||
|
||||
it 'extracts links from the post' do
|
||||
|
|
|
@ -15,6 +15,13 @@ describe DraftSequence do
|
|||
user.id = -99999
|
||||
2.times { expect(DraftSequence.next!(user, 'test')).to eq(0) }
|
||||
end
|
||||
|
||||
it 'updates draft count' do
|
||||
Draft.create!(user: user, draft_key: 'test', data: {})
|
||||
expect(user.reload.user_stat.draft_count).to eq(1)
|
||||
expect(DraftSequence.next!(user, 'test')).to eq 1
|
||||
expect(user.reload.user_stat.draft_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.current' do
|
||||
|
|
Loading…
Reference in New Issue