Merge branch 'optimise-runner-update-cached-info' into 'master'
Optimise runner update cached info See merge request gitlab-org/gitlab-ce!19187
This commit is contained in:
commit
cb77087246
3 changed files with 25 additions and 12 deletions
|
@ -219,10 +219,8 @@ module Ci
|
||||||
|
|
||||||
cache_attributes(values)
|
cache_attributes(values)
|
||||||
|
|
||||||
if persist_cached_data?
|
# We save data without validation, it will always change due to `contacted_at`
|
||||||
self.assign_attributes(values)
|
self.update_columns(values) if persist_cached_data?
|
||||||
self.save if self.changed?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def pick_build!(build)
|
def pick_build!(build)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Update runner cached informations without performing validations
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: performance
|
|
@ -549,7 +549,7 @@ describe Ci::Runner do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#update_cached_info' do
|
describe '#update_cached_info' do
|
||||||
let(:runner) { create(:ci_runner) }
|
let(:runner) { create(:ci_runner, :project) }
|
||||||
|
|
||||||
subject { runner.update_cached_info(architecture: '18-bit') }
|
subject { runner.update_cached_info(architecture: '18-bit') }
|
||||||
|
|
||||||
|
@ -570,17 +570,22 @@ describe Ci::Runner do
|
||||||
runner.contacted_at = 2.hours.ago
|
runner.contacted_at = 2.hours.ago
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates database' do
|
context 'with invalid runner' do
|
||||||
expect_redis_update
|
before do
|
||||||
|
runner.projects = []
|
||||||
expect { subject }.to change { runner.reload.read_attribute(:contacted_at) }
|
|
||||||
.and change { runner.reload.read_attribute(:architecture) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates cache' do
|
it 'still updates redis cache and database' do
|
||||||
expect_redis_update
|
expect(runner).to be_invalid
|
||||||
|
|
||||||
subject
|
expect_redis_update
|
||||||
|
does_db_update
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'updates redis cache and database' do
|
||||||
|
expect_redis_update
|
||||||
|
does_db_update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -590,6 +595,11 @@ describe Ci::Runner do
|
||||||
expect(redis).to receive(:set).with(redis_key, anything, any_args)
|
expect(redis).to receive(:set).with(redis_key, anything, any_args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def does_db_update
|
||||||
|
expect { subject }.to change { runner.reload.read_attribute(:contacted_at) }
|
||||||
|
.and change { runner.reload.read_attribute(:architecture) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#destroy' do
|
||||||
|
|
Loading…
Reference in a new issue