You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(system): collapse dashboard user metrics into one query #790
GET /api/system/users builds dashboard user metrics with two sequential database statements: one grouped status count and one recent-online count. The dashboard polls this endpoint every five seconds and the Statistics page every two seconds, so every active dashboard continuously multiplies database round trips.
The current queries return correct data and use admin-scoped indexes where available, but the two scans/round trips are avoidable because all metrics come from the same filtered users relation.
Proposed solution
Compute total, per-status, and recent-online counts with one conditional-aggregation statement.
Preserve global and admin-scoped behavior, the two-minute online window, and the existing API response.
Keep the result fully fresh; do not introduce a cache or stale response window.
Add regression coverage for metric values, admin isolation, empty datasets, and a one-SELECT query budget.
Validate generated SQL on supported dialects and benchmark the consolidated query against the current two-query path.
Implementation note: a 500k-row synthetic benchmark showed that one conditional table scan improved the global path (~47%) but regressed the admin-scoped path because it stopped using the existing (admin_id, status) and (admin_id, online_at) indexes. The implementation will therefore remain one SQL statement while using conditional aggregation globally and index-friendly scalar aggregates for scoped requests. This preserves the one-round-trip acceptance criterion without trading away scoped query performance.
Activity
dr-hoseyn commentedon Aug 14, 2026
Implementation note: a 500k-row synthetic benchmark showed that one conditional table scan improved the global path (~47%) but regressed the admin-scoped path because it stopped using the existing
(admin_id, status)and(admin_id, online_at)indexes. The implementation will therefore remain one SQL statement while using conditional aggregation globally and index-friendly scalar aggregates for scoped requests. This preserves the one-round-trip acceptance criterion without trading away scoped query performance.