-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Load heatmap data asynchronously #36622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
af61f6f
Load heatmap data asynchronously to improve page render performance
silverwind 24fe193
Fix org/team dashboard heatmap URLs missing /org prefix
silverwind 661c0df
Use url.PathEscape for heatmap URLs and check resp.ok in frontend
silverwind 9576044
Apply suggestion from @silverwind
silverwind 4c6c514
Add HeatmapResponse type in heatmap.ts
silverwind 3623f5e
Add example values comment to HeatmapResponse
silverwind 6971611
Remove unnecessary heatmap JSON helper functions from model layer
silverwind d095a04
Simplify heatmap URL calculation and add HeatmapDataToJSON helper
silverwind d5e8068
Extract shared writeHeatmapJSON helper, remove model changes
silverwind 361df30
Use /-/ separator in dashboard heatmap routes to avoid {team} conflict
silverwind f977a7d
Use HomeLink() for heatmap URLs and reuse profile endpoint for non-or…
silverwind 5839a89
Fix org dashboard heatmap URL by using OrganisationLink() instead of …
silverwind 592ed2c
Add integration tests for all 3 web heatmap endpoints
silverwind 215911c
Apply suggestion from @silverwind
silverwind fc7ab0b
refactor
wxiaoguang 9561d53
Merge branch 'main' into hm
silverwind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package user | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/url" | ||
|
|
||
| activities_model "code.gitea.io/gitea/models/activities" | ||
| "code.gitea.io/gitea/modules/setting" | ||
| "code.gitea.io/gitea/services/context" | ||
| ) | ||
|
|
||
| func prepareHeatmapURL(ctx *context.Context) { | ||
| ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap | ||
| if !setting.Service.EnableUserHeatmap { | ||
| return | ||
| } | ||
|
|
||
| if ctx.Org.Organization == nil { | ||
| // for individual user | ||
| ctx.Data["HeatmapURL"] = ctx.Doer.HomeLink() + "/-/heatmap" | ||
| return | ||
| } | ||
|
|
||
| // for org or team | ||
| heatmapURL := ctx.Org.Organization.OrganisationLink() + "/dashboard/-/heatmap" | ||
| if ctx.Org.Team != nil { | ||
| heatmapURL += "/" + url.PathEscape(ctx.Org.Team.LowerName) | ||
| } | ||
| ctx.Data["HeatmapURL"] = heatmapURL | ||
| } | ||
|
|
||
| func writeHeatmapJSON(ctx *context.Context, hdata []*activities_model.UserHeatmapData) { | ||
| data := make([][2]int64, len(hdata)) | ||
| var total int64 | ||
| for i, v := range hdata { | ||
| data[i] = [2]int64{int64(v.Timestamp), v.Contributions} | ||
| total += v.Contributions | ||
| } | ||
| ctx.JSON(http.StatusOK, map[string]any{ | ||
| "heatmapData": data, | ||
| "totalContributions": total, | ||
| }) | ||
| } | ||
|
|
||
| // DashboardHeatmap returns heatmap data as JSON, for the individual user, organization or team dashboard. | ||
| func DashboardHeatmap(ctx *context.Context) { | ||
| if !setting.Service.EnableUserHeatmap { | ||
| ctx.NotFound(nil) | ||
| return | ||
| } | ||
| var data []*activities_model.UserHeatmapData | ||
| var err error | ||
| if ctx.Org.Organization == nil { | ||
| data, err = activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer) | ||
| } else { | ||
| data, err = activities_model.GetUserHeatmapDataByOrgTeam(ctx, ctx.Org.Organization, ctx.Org.Team, ctx.Doer) | ||
| } | ||
| if err != nil { | ||
| ctx.ServerError("GetUserHeatmapData", err) | ||
| return | ||
| } | ||
| writeHeatmapJSON(ctx, data) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package integration | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "code.gitea.io/gitea/modules/timeutil" | ||
| "code.gitea.io/gitea/tests" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestHeatmapEndpoints(t *testing.T) { | ||
| defer tests.PrepareTestEnv(t)() | ||
|
|
||
| // Mock time so fixture actions fall within the heatmap's time window | ||
| timeutil.MockSet(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)) | ||
| defer timeutil.MockUnset() | ||
|
|
||
| session := loginUser(t, "user2") | ||
|
|
||
| t.Run("UserProfile", func(t *testing.T) { | ||
| defer tests.PrintCurrentTest(t)() | ||
| req := NewRequest(t, "GET", "/user2/-/heatmap") | ||
| resp := session.MakeRequest(t, req, http.StatusOK) | ||
|
|
||
| var result map[string]any | ||
| DecodeJSON(t, resp, &result) | ||
| assert.Contains(t, result, "heatmapData") | ||
| assert.Contains(t, result, "totalContributions") | ||
| assert.Positive(t, result["totalContributions"]) | ||
| }) | ||
|
|
||
| t.Run("OrgDashboard", func(t *testing.T) { | ||
| defer tests.PrintCurrentTest(t)() | ||
| req := NewRequest(t, "GET", "/org/org3/dashboard/-/heatmap") | ||
| resp := session.MakeRequest(t, req, http.StatusOK) | ||
|
|
||
| var result map[string]any | ||
| DecodeJSON(t, resp, &result) | ||
| assert.Contains(t, result, "heatmapData") | ||
| assert.Contains(t, result, "totalContributions") | ||
| }) | ||
|
|
||
| t.Run("OrgTeamDashboard", func(t *testing.T) { | ||
| defer tests.PrintCurrentTest(t)() | ||
| req := NewRequest(t, "GET", "/org/org3/dashboard/-/heatmap/team1") | ||
| resp := session.MakeRequest(t, req, http.StatusOK) | ||
|
|
||
| var result map[string]any | ||
| DecodeJSON(t, resp, &result) | ||
| assert.Contains(t, result, "heatmapData") | ||
| assert.Contains(t, result, "totalContributions") | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.