Sha256: e79453d7cb7a12b60e392f76ea999a221c4d7aab3b15d886e3fd402af894609d

Contents?: true

Size: 737 Bytes

Versions: 8

Compression:

Stored size: 737 Bytes

Contents

class ApplicationController < ActionController::Base
  AVAILABLE_LOADERS = %w[N+1 precount eager_count].freeze
  DEFAULT_LOADER    = 'N+1'

  def index
    @tweets = Tweet.all
    case loader
    when 'precount'
      @tweets = @tweets.precount(:replies).preload(in_reply_to: :favorites_count)
    when 'eager_count'
      @tweets = @tweets.eager_count(:replies).eager_load(in_reply_to: :favorites_count)
    end
  end

  def precount?
    loader == 'precount'
  end
  helper_method :precount?

  def eager_count?
    loader == 'eager_count'
  end
  helper_method :eager_count?

  def loader
    if AVAILABLE_LOADERS.include?(params[:loader])
      params[:loader]
    else
      DEFAULT_LOADER
    end
  end
  helper_method :loader
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
activerecord-precount-0.7.0 sample/app/controllers/application_controller.rb
activerecord-precount-0.7.0.beta1 sample/app/controllers/application_controller.rb
activerecord-precount-0.6.3 sample/app/controllers/application_controller.rb
activerecord-precount-0.6.2 sample/app/controllers/application_controller.rb
activerecord-precount-0.6.1 sample/app/controllers/application_controller.rb
activerecord-precount-0.6.0 sample/app/controllers/application_controller.rb
activerecord-precount-0.5.1 sample/app/controllers/application_controller.rb
activerecord-precount-0.5.0 sample/app/controllers/application_controller.rb