2018-04-18 15:30:41 -04:00
|
|
|
class AdminDashboardNextData
|
|
|
|
include StatsCacheable
|
|
|
|
|
2018-05-16 20:25:50 -04:00
|
|
|
REPORTS = %w{
|
|
|
|
page_view_total_reqs
|
|
|
|
visits
|
|
|
|
time_to_first_response
|
|
|
|
likes
|
|
|
|
flags
|
|
|
|
user_to_user_private_messages_with_replies
|
|
|
|
}
|
2018-04-18 15:30:41 -04:00
|
|
|
|
|
|
|
def initialize(opts = {})
|
|
|
|
@opts = opts
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.fetch_stats
|
|
|
|
AdminDashboardNextData.new.as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.stats_cache_key
|
|
|
|
'dash-next-stats'
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_json(_options = nil)
|
|
|
|
@json ||= {
|
2018-05-03 09:41:41 -04:00
|
|
|
reports: AdminDashboardNextData.reports(REPORTS),
|
2018-04-18 15:30:41 -04:00
|
|
|
last_backup_taken_at: last_backup_taken_at,
|
|
|
|
updated_at: Time.zone.now.as_json
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_backup_taken_at
|
|
|
|
if last_backup = Backup.all.last
|
|
|
|
File.ctime(last_backup.path).utc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reports(source)
|
|
|
|
source.map { |type| Report.find(type).as_json }
|
|
|
|
end
|
|
|
|
end
|