Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

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

ulferts2744673ec861
diff --git a/app/workers/attachments/finish_direct_upload_job.rb b/app/workers/attachments/finish_direct_upload_job.rb
index 7648b6dc906..45a21e69b45 100644
--- a/app/workers/attachments/finish_direct_upload_job.rb
+++ b/app/workers/attachments/finish_direct_upload_job.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
diff --git a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb
index b9fbe11320a..6e6ed6b0d6a 100644
--- a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb
+++ b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb
@@ -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