mirror of
https://github.com/discourse/discourse.git
synced 2025-04-11 08:02:24 +08:00
fix spec
This commit is contained in:
parent
f69c289fcf
commit
581d362627
@ -16,7 +16,7 @@ class Report
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.cache_key(report)
|
def self.cache_key(report)
|
||||||
"reports:#{report.type}:#{report.start_date.strftime("%Y%m%d")}:#{report.end_date.strftime("%Y%m%d")}"
|
"reports:#{report.type}:#{report.start_date.to_date.strftime("%Y%m%d")}:#{report.end_date.to_date.strftime("%Y%m%d")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.clear_cache
|
def self.clear_cache
|
||||||
@ -56,8 +56,8 @@ class Report
|
|||||||
|
|
||||||
# Load the report
|
# Load the report
|
||||||
report = Report.new(type)
|
report = Report.new(type)
|
||||||
report.start_date = opts[:start_date].to_date if opts[:start_date]
|
report.start_date = opts[:start_date] if opts[:start_date]
|
||||||
report.end_date = opts[:end_date].to_date if opts[:end_date]
|
report.end_date = opts[:end_date] if opts[:end_date]
|
||||||
report.category_id = opts[:category_id] if opts[:category_id]
|
report.category_id = opts[:category_id] if opts[:category_id]
|
||||||
report.group_id = opts[:group_id] if opts[:group_id]
|
report.group_id = opts[:group_id] if opts[:group_id]
|
||||||
report.async = opts[:async] || false
|
report.async = opts[:async] || false
|
||||||
@ -65,10 +65,12 @@ class Report
|
|||||||
|
|
||||||
if respond_to?(report_method)
|
if respond_to?(report_method)
|
||||||
cached_report = Discourse.cache.read(cache_key(report))
|
cached_report = Discourse.cache.read(cache_key(report))
|
||||||
|
if report.async
|
||||||
if cached_report
|
if cached_report
|
||||||
return cached_report
|
return cached_report
|
||||||
elsif report.async
|
else
|
||||||
Jobs.enqueue(:retrieve_report, opts.merge(report_type: type))
|
Jobs.enqueue(:retrieve_report, opts.merge(report_type: type))
|
||||||
|
end
|
||||||
else
|
else
|
||||||
send(report_method, report)
|
send(report_method, report)
|
||||||
end
|
end
|
||||||
@ -125,6 +127,7 @@ class Report
|
|||||||
basic_report_about report, User.real, :count_by_signup_date, report.start_date, report.end_date, report.group_id
|
basic_report_about report, User.real, :count_by_signup_date, report.start_date, report.end_date, report.group_id
|
||||||
add_counts report, User.real, 'users.created_at'
|
add_counts report, User.real, 'users.created_at'
|
||||||
else
|
else
|
||||||
|
|
||||||
report_about report, User.real, :count_by_signup_date
|
report_about report, User.real, :count_by_signup_date
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -245,6 +248,7 @@ class Report
|
|||||||
|
|
||||||
def self.basic_report_about(report, subject_class, report_method, *args)
|
def self.basic_report_about(report, subject_class, report_method, *args)
|
||||||
report.data = []
|
report.data = []
|
||||||
|
|
||||||
subject_class.send(report_method, *args).each do |date, count|
|
subject_class.send(report_method, *args).each do |date, count|
|
||||||
report.data << { x: date, y: count }
|
report.data << { x: date, y: count }
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user