redding/mr — pull request #189 by jcredding (2014-03-17 19:47:52+00:00)
Title: Update query counting, better support grouped queries

This updates MR's query counting to better support grouped
queries. Previously, it would use the hash returned by
ActiveRecord and count the results. This works, but is not
efficient and wasn't well thought out. This updates it to build
a wrapper query that uses the original query as a subquery.
It counts the wrapper query results which are not effected by the
`GROUP BY` statements in the subquery. This is significantly more
efficient than the previous implementation. In a test case, it
reduced the page load time from 11s to 6s. This also changes
`Query#count` not just `PagedQuery#total_count`.

This also updates all query counts to be slightly more efficient
by dropping any custom selects and orders. This doesn't change
much on non-grouped queries, but did speed up the grouped queries
count when a lot of select or order statements were part of the
query.

Finally, this cleaned up the query tests to the latest conventions.

@kellyredding - Ready for review.