summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-10-29 09:54:33 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-11-27 16:56:38 +0100
commitb87266d9caec71c0d27ce24dc2629304d02d5a30 (patch)
tree43fa90087b4553cd2d12bd2ff9bfa4a78f4f3ff8
parent55abda19c23467b818de7663f791e7db5c71e118 (diff)
downloadgitlab-ce-b87266d9caec71c0d27ce24dc2629304d02d5a30.tar.gz
Fix rubocop offenses.
-rw-r--r--lib/gitlab/database/count.rb8
-rw-r--r--spec/lib/gitlab/database/count_spec.rb8
2 files changed, 9 insertions, 7 deletions
diff --git a/lib/gitlab/database/count.rb b/lib/gitlab/database/count.rb
index 8af462da4a6..ed3510f1afc 100644
--- a/lib/gitlab/database/count.rb
+++ b/lib/gitlab/database/count.rb
@@ -40,7 +40,7 @@ module Gitlab
if strategy.enabled?
models_with_missing_counts = models - counts_by_model.keys
- return counts_by_model if models_with_missing_counts.empty?
+ break if models_with_missing_counts.empty?
counts = strategy.new(models_with_missing_counts).count
@@ -139,6 +139,7 @@ module Gitlab
LEFT JOIN pg_stat_user_tables ON pg_class.relname = pg_stat_user_tables.relname
WHERE pg_class.relname IN (#{table_names.map { |table| "'#{table}'" }.join(',')})
SQL
+
if check_statistics
base_query + "AND (last_vacuum > #{time} OR last_autovacuum > #{time} OR last_analyze > #{time} OR last_autoanalyze > #{time})"
else
@@ -177,6 +178,7 @@ module Gitlab
end
private
+
def perform_count(model, estimate)
# If we estimate 0, we may not have statistics at all. Don't use them.
return nil unless estimate && estimate > 0
@@ -193,10 +195,10 @@ module Gitlab
def tablesample_count(model, estimate)
portion = (TABLESAMPLE_ROW_TARGET.to_f / estimate).round(4)
- inverse = 1/portion
+ inverse = 1 / portion
query = <<~SQL
SELECT (COUNT(*)*#{inverse})::integer AS count
- FROM #{model.table_name} TABLESAMPLE SYSTEM (#{portion*100})
+ FROM #{model.table_name} TABLESAMPLE SYSTEM (#{portion * 100})
SQL
rows = ActiveRecord::Base.connection.select_all(query)
diff --git a/spec/lib/gitlab/database/count_spec.rb b/spec/lib/gitlab/database/count_spec.rb
index 5f2eab0e5bc..90a82aadc7c 100644
--- a/spec/lib/gitlab/database/count_spec.rb
+++ b/spec/lib/gitlab/database/count_spec.rb
@@ -10,7 +10,7 @@ describe Gitlab::Database::Count do
context '.approximate_counts' do
context 'selecting strategies' do
- let(:strategies) { [double('s1', :enabled? => true), double('s2', :enabled? => false)] }
+ let(:strategies) { [double('s1', enabled?: true), double('s2', enabled?: false)] }
it 'uses only enabled strategies' do
expect(strategies[0]).to receive(:new).and_return(double('strategy1', count: {}))
@@ -25,8 +25,8 @@ describe Gitlab::Database::Count do
let(:strategies) do
[
- double('s1', :enabled? => true, new: first_strategy),
- double('s2', :enabled? => true, new: second_strategy)
+ double('s1', enabled?: true, new: first_strategy),
+ double('s2', enabled?: true, new: second_strategy)
]
end
@@ -62,7 +62,7 @@ describe Gitlab::Database::Count do
describe '#count' do
it 'counts all models' do
- models.each { |model| expect(model).to receive(:count).and_call_original }
+ expect(models).to all(receive(:count).and_call_original)
expect(subject).to eq({ Project => 3, Identity => 1 })
end