Skip to content

Commit

Permalink
Wrap cancel tree in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lomky committed Jan 16, 2020
1 parent 776150b commit cb7a19b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,15 @@ def cancel_task_and_child_subtasks
# by avoiding callbacks, we aren't saving PaperTrail versions
# Manually save the state before and after.
tasks = Task.open.where(id: descendant_ids)
tasks.each { |task| task.paper_trail.save_with_version }
tasks.update_all(
status: Constants.TASK_STATUSES.cancelled,
closed_at: Time.zone.now
)
tasks.each { |task| task.reload.paper_trail.save_with_version }

transaction do
tasks.each { |task| task.paper_trail.save_with_version }
tasks.update_all(
status: Constants.TASK_STATUSES.cancelled,
closed_at: Time.zone.now
)
tasks.each { |task| task.reload.paper_trail.save_with_version }
end
end

def timeline_title
Expand Down

0 comments on commit cb7a19b

Please sign in to comment.