diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-29 23:00:39 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-01-29 23:00:39 +0100 |
commit | 3be6f68a33d163922a78c51928980efc57a3efb5 (patch) | |
tree | d40b956a044a4b97ae1b4b091ac4e6687137d4b7 | |
parent | b88103e4075678d032d7d7350caaece4a3091328 (diff) | |
download | gitlab-ce-3be6f68a33d163922a78c51928980efc57a3efb5.tar.gz |
Make Ci::Runner#online? slightly more performant
This is a small refactor to avoid querying Redis when we know there's
nothing in it.
-rw-r--r-- | app/models/ci/runner.rb | 2 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 7cf36c0bfe0..f6d51fabd69 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -97,7 +97,7 @@ module Ci end def online? - cached_contacted_at && cached_contacted_at > self.class.contact_time_deadline + contacted_at && cached_contacted_at > self.class.contact_time_deadline end def status diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 14747a23c82..99b4a82da88 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -128,6 +128,7 @@ describe Ci::Runner do context 'with cache value' do context 'contacted long time ago time' do before do + runner.contacted_at = 1.year.ago stub_redis_runner_contacted_at(1.year.ago.to_s) end @@ -136,6 +137,7 @@ describe Ci::Runner do context 'contacted 1s ago' do before do + runner.contacted_at = 50.minutes.ago stub_redis_runner_contacted_at(1.second.ago.to_s) end |