0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/spec/services/admin_dashboard_section_loader_spec.rb
Natalie Tay da2e0fe3bc
PERF: Parallelize section loading in new dashboard (#40970)
Since we're loading different sections at once on the dash, it might
make sense to load them in parallel.

| Metric | Current parallel | Baseline serial | Delta |
|---|---:|---:|---:|
| Runs | 2543, 1558, 1693, 1336, 1383 ms | 3104, 1985, 2147, 2428, 2372
ms | |
| Min | 1336 ms | 1985 ms | -649 ms |
| Median | 1558 ms | 2372 ms | -814 ms (-34.3%) |
| Average | 1703 ms | 2407 ms | -704 ms (-29.2%) |
| Max | 2543 ms | 3104 ms | -561 ms |
2026-06-17 16:29:10 +08:00

48 lines
1.5 KiB
Ruby
Vendored

# frozen_string_literal: true
describe AdminDashboardSectionLoader do
fab!(:admin)
after do
if thread_pool = described_class.instance_variable_get(:@thread_pool)
thread_pool.shutdown
thread_pool.wait_for_termination(timeout: 1)
described_class.remove_instance_variable(:@thread_pool)
end
end
describe ".build" do
it "ensures the sections are built in order with current user and dates" do
AdminDashboardSiteTraffic
.expects(:build)
.with do |kwargs|
kwargs[:start_date] == "2026-05-01" && kwargs[:end_date] == "2026-05-07" &&
kwargs[:guardian].is_a?(Guardian) && kwargs[:guardian].user.id == admin.id
end
.returns({ value: "traffic" })
AdminDashboardEngagement
.expects(:build)
.with(start_date: "2026-05-01", end_date: "2026-05-07", current_user: admin)
.returns({ value: "engagement" })
AdminDashboardSearch
.expects(:build)
.with(start_date: "2026-05-01", end_date: "2026-05-07")
.returns({ value: "search" })
expect(
described_class.build(
section_ids: %w[traffic engagement search],
current_user: admin,
start_date: "2026-05-01",
end_date: "2026-05-07",
),
).to eq(
[
{ id: "traffic", data: { value: "traffic" } },
{ id: "engagement", data: { value: "engagement" } },
{ id: "search", data: { value: "search" } },
],
)
end
end
end