Skip to content
Snippets Groups Projects
Commit ad2919bd authored by Steve Abrams's avatar Steve Abrams
Browse files

Improve EnqueuerWorker query performance

Updates the EnqueuerWorker query to use LIMIT 10 to
allow it to find the right index due to postgres incorrectly
calculating the optimal query plan.
parent 77ad7b23
No related branches found
No related tags found
1 merge request!90735Improve EnqueuerWorker query performance
......@@ -125,17 +125,18 @@ def maximum_capacity
def next_repository
strong_memoize(:next_repository) do
# Using .limit(2)[0] instead of take here. Using a LIMIT 1 caused the query planner to
# use an inefficient sequential scan instead of picking an index. LIMIT 2 works around
# Using .limit(25)[0] instead of take here. Using a LIMIT 1 and 2 caused the query planner to
# use an inefficient sequential scan instead of picking an index. LIMIT 25 works around
# this issue.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87733 for details.
ContainerRepository.ready_for_import.limit(2)[0] # rubocop:disable CodeReuse/ActiveRecord
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87733 and
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/90735 for details.
ContainerRepository.ready_for_import.limit(25)[0] # rubocop:disable CodeReuse/ActiveRecord
end
end
def next_aborted_repository
strong_memoize(:next_aborted_repository) do
ContainerRepository.with_migration_state('import_aborted').limit(2)[0] # rubocop:disable CodeReuse/ActiveRecord
ContainerRepository.with_migration_state('import_aborted').limit(25)[0] # rubocop:disable CodeReuse/ActiveRecord
end
end
......
......@@ -158,7 +158,7 @@
expect(worker).to receive(:handle_next_migration).exactly(3).times.and_call_original
expect { subject }.to make_queries_matching(/LIMIT 2/)
expect { subject }.to make_queries_matching(/LIMIT 25/)
expect(container_repository.reload).to be_pre_importing
expect(container_repository2.reload).to be_pre_importing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment