avoid updating the lock version on finishing an attachment upload (#8934)

If the lock version is increased, it might happen while the user is still editing the description. The user might have added an image to the description and continues typing. In the backend, the FinishDirectUploadJob is run before the user presses the checkmark to send the updated description. In that case, a 409 conflict would be signaled if the lock version were to be updated in the meantime.
pull/8936/head
ulferts 4 years ago committed by GitHub
parent 38cae188ad
commit 2744673ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/workers/attachments/finish_direct_upload_job.rb
  2. 2
      spec/workers/attachments/finish_direct_upload_job_integration_spec.rb

@ -78,10 +78,19 @@ class Attachments::FinishDirectUploadJob < ApplicationJob
# This remains a TODO.
# But with the timestamp update in place as it is, at least the collapsing of aggregated journals
# from days before with the newly uploaded attachment is prevented.
journable.touch
touch_journable(journable)
Journals::CreateService
.new(journable, attachment.author)
.call
end
def touch_journable(journable)
# Not using touch here on purpose,
# as to avoid changing lock versions on the journables for this change
attributes = journable.send(:timestamp_attributes_for_update_in_model)
timestamps = attributes.index_with { Time.now }
journable.update_columns(timestamps) if timestamps.any?
end
end

@ -93,7 +93,7 @@ describe Attachments::FinishDirectUploadJob, 'integration', type: :job do
container.reload
expect(container.lock_version)
.to eql 1
.to eql 0
end
end

Loading…
Cancel
Save