~cytrogen/masto-fe

770fd993ecaf2f35ea08fc7ad7a22711417fe3e5 — Jakob Gillich 2 years ago e95d25e
Fix importer returning negative row estimates (#27258)

1 files changed, 3 insertions(+), 1 deletions(-)

M app/lib/importer/base_importer.rb
M app/lib/importer/base_importer.rb => app/lib/importer/base_importer.rb +3 -1
@@ 34,7 34,9 @@ class Importer::BaseImporter
  # Estimate the amount of documents that would be indexed. Not exact!
  # @returns [Integer]
  def estimate!
    ActiveRecord::Base.connection_pool.with_connection { |connection| connection.select_one("SELECT reltuples AS estimate FROM pg_class WHERE relname = '#{index.adapter.target.table_name}'")['estimate'].to_i }
    reltuples = ActiveRecord::Base.connection_pool.with_connection { |connection| connection.select_one("SELECT reltuples FROM pg_class WHERE relname = '#{index.adapter.target.table_name}'")['reltuples'].to_i }
    # If the table has never yet been vacuumed or analyzed, reltuples contains -1
    [reltuples, 0].max
  end

  # Import data from the database into the index