Page MenuHomePhabricator

Optimize /api/stats endpoint to reduce long load time on stats page
Closed, ResolvedPublic

Description

Difficulty: Difficult

Description:
The Stats page (/stats) currently takes a long time to load due to a single API endpoint (/api/stats) serving all chart and table data at once.
A recent network request shows a 19.34-second load time, which impacts user experience — especially on slower connections or mobile devices.

The /api/stats endpoint currently returns a large JSON payload containing data for multiple chart components (averages, detailed_stats, distribution, growth_trends, and yoy_change). Each graph and table consumes part of this data, but all are fetched together on initial load.

Splitting the endpoint into smaller, independent ones for each visualization could improve perceived load time and allow progressive rendering of charts.

Request Example:

Suggested Improvement:

Split the /api/stats endpoint into smaller endpoints, for example:

  • /api/stats/growth_trends
  • /api/stats/yoy_change
  • /api/stats/distribution
  • /api/stats/averages
  • /api/stats/detailed

Implement parallel AJAX requests in the frontend (stat.html) using $.when() or Promise.all() so charts load independently.

Optionally add lazy-loading for non-critical charts (e.g., table data only after charts load).

Details

Related Changes in GitLab:
TitleReferenceAuthorSource BranchDest Branch
Refactor statistics API and frontend to improve performance and organizationtoolforge-repos/isa!26gopavasanthT409878main
Customize query in GitLab

Event Timeline

gopavasanth opened https://gitlab.wikimedia.org/toolforge-repos/isa/-/merge_requests/26

Refactor statistics API and frontend to improve performance and organization

swayamagrahari merged https://gitlab.wikimedia.org/toolforge-repos/isa/-/merge_requests/26

Refactor statistics API and frontend to improve performance and organization

Hey @Gopavasanth thanks for the patch, can't stress how helpful the patch is. The stats page is now fully functional and doesnot require a long wait to load the stats.
Status: Accepted ✅