diff --git a/lib/gitlab/database/count.rb b/lib/gitlab/database/count.rb index 01fabcced65..8af462da4a6 100644 --- a/lib/gitlab/database/count.rb +++ b/lib/gitlab/database/count.rb @@ -172,6 +172,10 @@ module Gitlab {} end + def self.enabled? + Gitlab::Database.postgresql? && Feature.enabled?(:tablesample_counts) + end + private def perform_count(model, estimate) # If we estimate 0, we may not have statistics at all. Don't use them. diff --git a/spec/lib/gitlab/database/count_spec.rb b/spec/lib/gitlab/database/count_spec.rb index d6668cee23e..5f2eab0e5bc 100644 --- a/spec/lib/gitlab/database/count_spec.rb +++ b/spec/lib/gitlab/database/count_spec.rb @@ -163,6 +163,10 @@ describe Gitlab::Database::Count do end describe '.enabled?' do + before do + stub_feature_flags(tablesample_counts: true) + end + it 'is enabled for PostgreSQL' do allow(Gitlab::Database).to receive(:postgresql?).and_return(true)