1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Prefer to use ifs over Array#max for performance

https://gist.github.com/yuki24/e8d89597efa0fbdfe775
This commit is contained in:
Yuki Nishijima 2014-12-26 04:29:16 -08:00
parent 95bb76ec0b
commit 1fc1707acf
3 changed files with 3 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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