mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Fasterer: Enumerable#sort is slower
Enumerable#sort is slower than Enumerable#sort_by
This commit is contained in:
parent
5092b388fe
commit
405ad5a79f
2 changed files with 2 additions and 2 deletions
|
|
@ -22,7 +22,7 @@ module Stats
|
|||
|
||||
def find_top10_longest_running_projects
|
||||
projects = user.projects.order('created_at ASC')
|
||||
projects.sort{|a,b| b.running_time <=> a.running_time}.take(10)
|
||||
projects.sort_by{ |p| p.running_time }.take(10)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class User < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
def projects_in_state_by_position(state)
|
||||
self.sort{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
|
||||
self.sort_by{ |p| p.position }.select{ |p| p.state == state }
|
||||
end
|
||||
def next_from(project)
|
||||
self.offset_from(project, 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue