diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-10-29 09:54:33 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-12-03 21:26:51 +0100 |
commit | 9bb7c690c40a2a35829fc05015e5afcde578c38b (patch) | |
tree | 61367869996f0866fd53b69cca0027e3dc002682 /lib/gitlab/database | |
parent | 3266642739b58d8f54733bfcd399b523d963c2aa (diff) | |
download | gitlab-ce-9bb7c690c40a2a35829fc05015e5afcde578c38b.tar.gz |
Fix rubocop offenses.
Diffstat (limited to 'lib/gitlab/database')
-rw-r--r-- | lib/gitlab/database/count.rb | 8 |
1 files changed, 5 insertions, 3 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) |