mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-20 14:14:09 +01:00
Group project-related stats into a class.
Reduce number of instance variables available to the views. Replace raw SQL with AR-type query.
This commit is contained in:
parent
1e3782ce67
commit
8b1f0a34a0
4 changed files with 27 additions and 21 deletions
22
app/models/stats/projects.rb
Normal file
22
app/models/stats/projects.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
module Stats
|
||||
class Projects
|
||||
|
||||
attr_reader :user
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def runtime
|
||||
@runtime ||= user.projects.active.order('created_at ASC').limit(10)
|
||||
end
|
||||
|
||||
def actions
|
||||
@actions ||= Stats::TopProjectsQuery.new(user).result
|
||||
end
|
||||
|
||||
def actions_last30days
|
||||
@actions_last30days ||= Stats::TopProjectsQuery.new(user, 1.month.ago.beginning_of_day).result
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue