will_paginate on complex scopes may be slow (workaround)

will_paginate Show archive.org snapshot triggers a database query to determine the total number of entries (i.e. to let you display the number of search results). When you paginate complex scope (e.g. that has many includes), this query may take several seconds to complete.

If you encounter this behavior, a solution is to calculate the total count yourself and pass it to the pagination call:

scope = User.complex_scope_full_of_includes
total_number_of_users = scope.count
@users = scope.paginate(:total_entries => total_number_of_users)
Dominik Schöler About 12 years ago