mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: saving drafts unconditionally increases sequence
Previously we only changed sequence on ownership change, this cause a race condition between tabs where user could type for a long time without being warned of an out of date draft. This change is a radical change and we should watch closely. Code was already in place to track sequence on the client so no changes are needed there.
This commit is contained in:
@ -43,17 +43,17 @@ class Draft < ActiveRecord::Base
|
||||
raise Draft::OutOfSequence
|
||||
end
|
||||
|
||||
if owner && current_owner && current_owner != owner
|
||||
sequence += 1
|
||||
sequence += 1
|
||||
|
||||
DraftSequence.upsert({
|
||||
sequence: sequence,
|
||||
draft_key: key,
|
||||
user_id: user.id,
|
||||
},
|
||||
unique_by: [:user_id, :draft_key]
|
||||
)
|
||||
end
|
||||
# we need to keep upping our sequence on every save
|
||||
# if we do not do that there are bad race conditions
|
||||
DraftSequence.upsert({
|
||||
sequence: sequence,
|
||||
draft_key: key,
|
||||
user_id: user.id,
|
||||
},
|
||||
unique_by: [:user_id, :draft_key]
|
||||
)
|
||||
|
||||
DB.exec(<<~SQL, id: draft_id, sequence: sequence, data: data, owner: owner || current_owner)
|
||||
UPDATE drafts
|
||||
@ -337,7 +337,7 @@ end
|
||||
# data :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# sequence :integer default(0), not null
|
||||
# sequence :bigint default(0), not null
|
||||
# revisions :integer default(1), not null
|
||||
# owner :string
|
||||
#
|
||||
|
Reference in New Issue
Block a user