This project is archived and is in readonly mode.

#5958 ✓committed
Ivan Ukhov

Collection rendering with superfluous database queries

Reported by Ivan Ukhov | November 12th, 2010 @ 10:16 AM | in 3.x

When passing some Relation to render :collection => ..., it produces two queries. One for counting (SELECT COUNT) and another for fetching (just SELECT). For example:

render :partial => 'some_partial', :collection => SomeModel.some_scope

Suppose this is because of the following line:

https://github.com/rails/rails/blob/master/actionpack/lib/action_vi...

My workaround:

module ActionView
  module Partials
    class PartialRenderer
      private
      def collection
        c = if @object.respond_to?(:to_ary)
          @object
        elsif @options.key?(:collection)
          @options[:collection] || []
        end
        c.try :length
        c
      end
    end
  end
end

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Referenced by

Pages