Skip to content

Commit b9b6d0e

Browse files
committed
Remove superfluous db query (with 1=0 clause)
1 parent 14038c1 commit b9b6d0e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/cloud_controller/diego/tasks_sync.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def sync
3737
end
3838
end
3939

40-
TaskModel.where(guid: tasks_to_fail).each do |cc_task|
41-
cc_task.update(state: TaskModel::FAILED_STATE, failure_reason: BULKER_TASK_FAILURE)
40+
unless tasks_to_fail.empty?
41+
TaskModel.where(guid: tasks_to_fail).each do |cc_task|
42+
cc_task.update(state: TaskModel::FAILED_STATE, failure_reason: BULKER_TASK_FAILURE)
43+
end
4244
end
4345
end
4446

spec/unit/lib/cloud_controller/diego/tasks_sync_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ module Diego
3737
subject.sync
3838
end.not_to(change { task.reload.state })
3939
end
40+
41+
it 'does not query tasks with a 1=0 clause' do
42+
expect do
43+
subject.sync
44+
end.to have_queried_db_times(/select \* from .tasks. where \(1 = 0\)/i, 0)
45+
end
4046
end
4147

4248
context 'when a running CC task is missing from BBS' do

0 commit comments

Comments
 (0)