mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:59:51 +08:00
fix my totally broken ApplicationRequest.stats method
This commit is contained in:
parent
9a637836d0
commit
fcae399481
|
@ -102,26 +102,16 @@ class ApplicationRequest < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.stats
|
||||
@stats ||= begin
|
||||
s = HashWithIndifferentAccess.new({
|
||||
all_total: 0,
|
||||
all_30_days: 0,
|
||||
all_7_days: 0
|
||||
})
|
||||
s = HashWithIndifferentAccess.new({})
|
||||
|
||||
self.req_types.each do |key, i|
|
||||
query = self.where(req_type: i)
|
||||
s["#{key}_total"] = query.sum(:count)
|
||||
s["#{key}_30_days"] = query.where("date > ?", 30.days.ago).sum(:count)
|
||||
s["#{key}_7_days"] = query.where("date > ?", 7.days.ago).sum(:count)
|
||||
|
||||
s[:all_total] += s["#{key}_total"]
|
||||
s[:all_30_days] += s["#{key}_30_days"]
|
||||
s[:all_7_days] += s["#{key}_7_days"]
|
||||
end
|
||||
|
||||
s
|
||||
self.req_types.each do |key, i|
|
||||
query = self.where(req_type: i)
|
||||
s["#{key}_total"] = query.sum(:count)
|
||||
s["#{key}_30_days"] = query.where("date > ?", 30.days.ago).sum(:count)
|
||||
s["#{key}_7_days"] = query.where("date > ?", 7.days.ago).sum(:count)
|
||||
end
|
||||
|
||||
s
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user