amatsuda/kaminari — pull request #472 by sgtFloyd (2013-11-16 05:01:56+00:00)
Title: Don't calculate total_pages if one is provided in options

`scope.total_pages`, and therefore `scope.total_count`, is calculated for every `paginate`, causing an additional (potentially expensive) query against the scope as part of `total_count`.

**Example:**
```ruby
@scope = Post.where(name: 'test')
@total_count = @scope.count # 17,294,103
```
```haml
= paginate @scope.page(params[:page]), total_pages: (@total_count / 25.0).ceil
```

**Without patch:**
```log
(7.1ms) SELECT COUNT(`post`.`id`) FROM `post` WHERE (post.name = 'test')
(170.0ms) SELECT `post`.* FROM `post` WHERE (post.name = 'test')
(2.8ms) SELECT `post`.* FROM `post` WHERE (post.name = 'test') LIMIT 25 OFFSET 0
```

**With patch:**
```log
(7.1ms) SELECT COUNT(`post`.`id`) FROM `post` WHERE (post.name = 'test')
(2.8ms) SELECT `post`.* FROM `post` WHERE (post.name = 'test') LIMIT 25 OFFSET 0
```