Skip to content

Commit

Permalink
Destroy stack relations in batches
Browse files Browse the repository at this point in the history
  • Loading branch information
DazWorrall committed Nov 13, 2024
1 parent 29ff9ae commit 812fced
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/jobs/shipit/destroy_stack_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ def perform(stack)
commits_ids = Shipit::Commit.where(stack_id: stack.id).pluck(:id)
tasks_ids = Shipit::Task.where(stack_id: stack.id).pluck(:id)
commit_deployments_ids = Shipit::CommitDeployment.where(task_id: tasks_ids).pluck(:id)
Shipit::CommitDeploymentStatus.where(commit_deployment_id: commit_deployments_ids).delete_all
Shipit::CommitDeployment.where(id: commit_deployments_ids).delete_all
Shipit::Status.where(commit_id: commits_ids).delete_all
Shipit::Commit.where(id: commits_ids).delete_all
Shipit::CommitDeploymentStatus.where(commit_deployment_id: commit_deployments_ids).in_batches(&:delete_all)
Shipit::CommitDeployment.where(id: commit_deployments_ids).in_batches(&:delete_all)
Shipit::Status.where(commit_id: commits_ids).in_batches(&:delete_all)
Shipit::Commit.where(id: commits_ids).in_batches(&:delete_all)
Shipit::GithubHook.where(stack_id: stack.id).destroy_all
Shipit::Hook.where(stack_id: stack.id).delete_all
Shipit::MergeRequest.where(stack_id: stack.id).delete_all
Shipit::Hook.where(stack_id: stack.id).in_batches(&:delete_all)
Shipit::MergeRequest.where(stack_id: stack.id).in_batches(&:delete_all)
tasks_ids.each_slice(100) do |ids|
Shipit::OutputChunk.where(task_id: ids).delete_all
Shipit::Task.where(id: ids).delete_all
Shipit::OutputChunk.where(task_id: ids).in_batches(&:delete_all)
Shipit::Task.where(id: ids).in_batches(&:delete_all)
end
stack.destroy!
end
Expand Down

0 comments on commit 812fced

Please sign in to comment.