Load heatmap data asynchronously#36622
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors heatmap data loading from synchronous server-side rendering to asynchronous client-side fetching. The change significantly improves page load performance by moving an expensive database query off the critical rendering path. The heatmap data is now fetched via dedicated JSON endpoints after the page becomes visible to the user.
Changes:
- Introduced three new JSON endpoints for async heatmap data loading:
/user/heatmap(personal dashboard),/{org}/dashboard/heatmap(org dashboard), and/{username}/-/heatmap(user profile) - Converted heatmap data format from verbose JSON objects
[{"timestamp":N,"contributions":N},...]to compact tuple arrays[[timestamp,count],...]to reduce payload size - Modified frontend to fetch and render heatmap asynchronously with proper error handling
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| web_src/js/features/heatmap.ts | Made initHeatmap async, added data fetching via GET request, and converts compact array format to heatmap display format |
| templates/user/heatmap.tmpl | Replaced inline heatmap data with data-heatmap-url attribute and updated locale string to use placeholder |
| routers/web/web.go | Registered three new JSON endpoints for personal, org, and profile heatmap data |
| routers/web/user/profile.go | Added Heatmap handler for user profile, returns compact JSON format with permission checks |
| routers/web/user/home.go | Modified Dashboard to set heatmap URL instead of data, added DashboardHeatmap handler for async data fetching |
| models/activities/user_heatmap.go | Added heatmapDataJSON helper and two new JSON-returning functions for compact data format |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move heatmap data loading from synchronous server-side rendering to
async client-side fetch. The dashboard and user profile pages no longer
block on the expensive heatmap DB query during HTML generation. Instead,
the heatmap is loaded via dedicated JSON endpoints after the page is
visible.
Additionally, use a compact [[timestamp,count],...] JSON format instead
of [{"timestamp":N,"contributions":N},...] to reduce payload size.
Benchmark with 1M action rows (SQLite):
- Old sync page render: 535ms
- New async page render: 66ms (8x faster)
- Heatmap endpoint: 464ms (loaded after page is visible)
Fixes: go-gitea#21045
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The heatmap data URLs were built without the /org route prefix, causing 404 responses and JSON parse errors in the browser. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use OrganisationLink()/HomeLink() helpers which apply url.PathEscape for org, team, and user names in heatmap URL construction - Check resp.ok before parsing JSON response in heatmap.ts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: silverwind <me@silverwind.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move the [][2]int64 conversion inline into the route handlers instead of adding dedicated model functions for it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Diff is minimal now, everything is working. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…g dashboard
- Use HomeLink() instead of Req.URL.Path for stable URL construction
- Non-org dashboard reuses /{username}/-/heatmap profile endpoint
- Remove now-unused /user/heatmap route
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…HomeLink()
OrganisationLink() returns /org/{name} which matches the route prefix,
while HomeLink() returns /{name} which caused a 404.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Comments addressed and one regression from that fixed (org dashboard). Tests for the JSON endpoints incoming. |
Tests the profile, org dashboard, and org team dashboard heatmap JSON endpoints for correct status and response structure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: silverwind <me@silverwind.io>
|
The refactoring does:
|
When AI reaches this level, I can delegate my work to it. |
|
Thanks for cleaning up |
|
I tested all heatmaps, all working. |
Fixes: #21045
[[timestamp,count]]JSON format instead of[{"timestamp":N,"contributions":N}]to reduce payload size/api/v1/users/{username}/heatmap) remains unchangedBenchmark (1M action rows, SQLite)
🤖 Generated with Claude Code