mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
DAU/MAU reports previously calculated every requested date from the full user visit history, so dashboard requests became slower as that history grew. Persist the daily DAU and trailing-30-day MAU values and have the shared report read only those rollups. The scheduled job builds all existing history on its first successful run, then refreshes yesterday and today every three hours. Replacements are atomic, so a failed calculation leaves the previous report data intact.
39 lines
1.3 KiB
Ruby
Vendored
39 lines
1.3 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
describe Reports::DauByMau do
|
|
describe ".report_dau_by_mau" do
|
|
let(:report) { Report.find("dau_by_mau") }
|
|
|
|
it "returns an empty report with no data" do
|
|
expect(report.data).to be_blank
|
|
end
|
|
|
|
it "returns a report with data" do
|
|
freeze_time_safe
|
|
Fabricate(:user_visit_daily_rollup, date: 45.days.ago, dau: 1, mau: 1)
|
|
Fabricate(:user_visit_daily_rollup, date: 35.days.ago, dau: 1, mau: 2)
|
|
Fabricate(:user_visit_daily_rollup, date: 2.days.ago, dau: 2, mau: 2)
|
|
Fabricate(:user_visit_daily_rollup, date: 1.day.ago, dau: 1, mau: 3)
|
|
|
|
expect(report.data.first[:y]).to eq(100)
|
|
expect(report.data.last[:y]).to eq(33.34)
|
|
expect(report.prev30Days).to eq(75)
|
|
end
|
|
|
|
it "returns the current data and previous period average" do
|
|
Fabricate(:user_visit_daily_rollup, date: Date.new(2026, 4, 9), dau: 1, mau: 1)
|
|
Fabricate(:user_visit_daily_rollup, date: Date.new(2026, 4, 11), dau: 1, mau: 2)
|
|
|
|
report =
|
|
Report.find(
|
|
"dau_by_mau",
|
|
start_date: Time.zone.local(2026, 4, 10).beginning_of_day,
|
|
end_date: Time.zone.local(2026, 4, 11).end_of_day,
|
|
facets: [:prev_period],
|
|
)
|
|
|
|
expect(report.data).to eq([{ x: Date.new(2026, 4, 11), y: 50.0 }])
|
|
expect(report.prev_period).to eq(100)
|
|
end
|
|
end
|
|
end
|