Sha256: b669b233827b31353cfb7284b981ea4b53b08cbc89057d6b888993fb28c52e75
Contents?: true
Size: 781 Bytes
Versions: 13
Compression:
Stored size: 781 Bytes
Contents
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/arel # frozen_string_literal: true class Pagy # :nodoc: # Better performance of grouped ActiveRecord collections module ArelExtra private # Return Pagy object and paginated collection/results def pagy_arel(collection, **vars) vars[:count] ||= pagy_arel_count(collection) pagy(collection, **vars) end # 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).pick(sql).to_i end end end Backend.prepend ArelExtra end
Version data entries
13 entries across 13 versions & 1 rubygems