Commit 103f2243 authored by Stan Hu's avatar Stan Hu

Disable Rails SQL query cache when applying service templates

When the SQL query cache is active, the SELECT query for finding
projects to apply service templates returns the same values. This causes
an infinite loop because even though bulk INSERT queries are made, the
cached results never reflect that progress.  To fix this, we call
`Project.uncached` around the query to ensure new data is retrieved.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63595
parent e3eeb779
...@@ -24,7 +24,7 @@ module Projects ...@@ -24,7 +24,7 @@ module Projects
def propagate_projects_with_template def propagate_projects_with_template
loop do loop do
batch = project_ids_batch batch = Project.uncached { project_ids_batch }
bulk_create_from_template(batch) unless batch.empty? bulk_create_from_template(batch) unless batch.empty?
......
---
title: Disable Rails SQL query cache when applying service templates
merge_request: 30060
author:
type: security
...@@ -72,7 +72,7 @@ describe Projects::PropagateServiceTemplate do ...@@ -72,7 +72,7 @@ describe Projects::PropagateServiceTemplate do
expect(project.pushover_service.properties).to eq(service_template.properties) expect(project.pushover_service.properties).to eq(service_template.properties)
end end
describe 'bulk update' do describe 'bulk update', :use_sql_query_cache do
let(:project_total) { 5 } let(:project_total) { 5 }
before do before do
......
...@@ -215,6 +215,12 @@ RSpec.configure do |config| ...@@ -215,6 +215,12 @@ RSpec.configure do |config|
ActionController::Base.cache_store = caching_store ActionController::Base.cache_store = caching_store
end end
config.around(:each, :use_sql_query_cache) do |example|
ActiveRecord::Base.cache do
example.run
end
end
# The :each scope runs "inside" the example, so this hook ensures the DB is in the # The :each scope runs "inside" the example, so this hook ensures the DB is in the
# correct state before any examples' before hooks are called. This prevents a # correct state before any examples' before hooks are called. This prevents a
# problem where `ScheduleIssuesClosedAtTypeChange` (or any migration that depends # problem where `ScheduleIssuesClosedAtTypeChange` (or any migration that depends
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment