mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Prefer to use if
s over Array#max for performance
https://gist.github.com/yuki24/e8d89597efa0fbdfe775
This commit is contained in:
parent
95bb76ec0b
commit
1fc1707acf
3 changed files with 3 additions and 3 deletions
|
@ -11,7 +11,7 @@ module Kaminari
|
|||
# Model.page(5)
|
||||
eval <<-RUBY
|
||||
def self.#{Kaminari.config.page_method_name}(num = nil)
|
||||
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1)).extending do
|
||||
limit(default_per_page).offset(default_per_page * ((num = num.to_i - 1) < 0 ? 0 : num)).extending do
|
||||
include Kaminari::ActiveRecordRelationMethods
|
||||
include Kaminari::PageScopeMethods
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ module Kaminari
|
|||
# items at the specified "page"
|
||||
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||
def #{Kaminari.config.page_method_name}(num = 1)
|
||||
offset(limit_value * ([num.to_i, 1].max - 1))
|
||||
offset(limit_value * ((num = num.to_i - 1) < 0 ? 0 : num))
|
||||
end
|
||||
RUBY
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ module Kaminari
|
|||
|
||||
included do
|
||||
scope Kaminari.config.page_method_name, Proc.new {|num|
|
||||
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
|
||||
limit(default_per_page).offset(default_per_page * ((num = num.to_i - 1) < 0 ? 0 : num))
|
||||
} do
|
||||
include Kaminari::MongoidCriteriaMethods
|
||||
include Kaminari::PageScopeMethods
|
||||
|
|
Loading…
Reference in a new issue