module Pagy::ArelExtra

def pagy_arel_count(collection)

Count using Arel when grouping
def pagy_arel_count(collection)
  if collection.group_values.empty?
    # COUNT(*)
    collection.count(:all)
  else
    # COUNT(*) OVER ()
    sql = Arel.star.count.over(Arel::Nodes::Grouping.new([]))
    collection.unscope(:order).limit(1).pluck(sql).first.to_i
  end
end