first select than sort

sorting on a smaller collection is faster
This commit is contained in:
Reinier Balt 2015-08-19 15:21:11 +02:00
parent 405ad5a79f
commit d3aa73f783

View file

@ -34,7 +34,7 @@ class User < ActiveRecord::Base
} }
end end
def projects_in_state_by_position(state) def projects_in_state_by_position(state)
self.sort_by{ |p| p.position }.select{ |p| p.state == state } self.select{ |p| p.state == state }.sort_by{ |p| p.position }
end end
def next_from(project) def next_from(project)
self.offset_from(project, 1) self.offset_from(project, 1)