Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

AR: Do not spawn additional queries when rendering page_entries_info. #343

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
1 participant

sayap commented Oct 31, 2013

collection.first.class will spawn a LIMIT 1 query, while collection.empty?
will spawn a COUNT query. The latter is not a problem since a COUNT query is
needed anyway, so redundant ones will retrieve from cache. The former, however,
can add unnecessary load to the database.

As far as I can tell, ActiveRecord::Relation has a klass attribute since the
beginning, so it should be fine. The attribute is also aliased as model since
rails/rails#6606, though this change is only available
in Rails 4.x.

@sayap sayap AR: Do not spawn additional queries when rendering page_entries_info.
`collection.first.class` will spawn a LIMIT 1 query, while `collection.empty?`
will spawn a COUNT query. The latter is not a problem since a COUNT query is
needed anyway, so redundant ones will retrieve from cache. The former, however,
can add unnecessary load to the database.

As far as I can tell, ActiveRecord::Relation has a `klass` attribute since the
beginning, so it should be fine. The attribute is also aliased as `model` since
rails/rails#6606, though this change is only available
in Rails 4.x.
9076eb4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment