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)
|
# Model.page(5)
|
||||||
eval <<-RUBY
|
eval <<-RUBY
|
||||||
def self.#{Kaminari.config.page_method_name}(num = nil)
|
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::ActiveRecordRelationMethods
|
||||||
include Kaminari::PageScopeMethods
|
include Kaminari::PageScopeMethods
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,7 +35,7 @@ module Kaminari
|
||||||
# items at the specified "page"
|
# items at the specified "page"
|
||||||
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||||
def #{Kaminari.config.page_method_name}(num = 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
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Kaminari
|
||||||
|
|
||||||
included do
|
included do
|
||||||
scope Kaminari.config.page_method_name, Proc.new {|num|
|
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
|
} do
|
||||||
include Kaminari::MongoidCriteriaMethods
|
include Kaminari::MongoidCriteriaMethods
|
||||||
include Kaminari::PageScopeMethods
|
include Kaminari::PageScopeMethods
|
||||||
|
|
Loading…
Reference in a new issue