total_count_with_limit

in config/initializers/kaminari_active_record_relation_methods_with_limit.rb [9:36]


    def total_count_with_limit(column_name = :all, _options = nil) 
      return @total_count if defined?(@total_count) && @total_count

      
      if loaded?
        
        return @total_count = 0 if (current_page == 1) && @records.empty?
        
        return @total_count = (current_page - 1) * limit_value + @records.length if @records.any? && (@records.length < limit_value)
      end

      
      c = except(:offset, :limit, :order)
      
      c = c.except(:includes) unless references_eager_loaded_tables?
      
      
      c = c.limit(MAX_COUNT_LIMIT + 1).count(column_name)
      @total_count =
        if c.is_a?(Hash) || c.is_a?(ActiveSupport::OrderedHash)
          c.count
        elsif c.respond_to? :count
          c.count(column_name)
        else
          c
        end
    end