mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40: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
|
def find_top10_longest_running_projects
|
||||||
projects = user.projects.order('created_at ASC')
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
|
self.sort_by{ |p| p.position }.select{ |p| p.state == state }
|
||||||
end
|
end
|
||||||
def next_from(project)
|
def next_from(project)
|
||||||
self.offset_from(project, 1)
|
self.offset_from(project, 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue