From 12c2efb45c112baf6013c304c35cbd404f7be21a Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Nov 2020 23:00:16 +0100 Subject: [PATCH] Remove fetch request from heatmap (#13623) * Remove fetch request from heatmap Render heatmap data directly to HTML, eliminating one HTTP request on frontpage and user profile. Also added min-height to the container so the page content will no longer move after loading. * rename and error display * also log the js error * add error handler * remove useless inline style and hide divider on small screens * Update routers/user/home.go * Update routers/user/profile.go --- routers/user/home.go | 10 +++- routers/user/profile.go | 12 +++- templates/base/head.tmpl | 2 - templates/user/dashboard/dashboard.tmpl | 5 +- templates/user/{dashboard => }/heatmap.tmpl | 9 +-- templates/user/profile.tmpl | 5 +- web_src/js/components/ActivityHeatmap.vue | 25 +++----- web_src/js/features/heatmap.js | 23 ++++++++ web_src/js/features/userheatmap.js | 10 ---- web_src/js/index.js | 4 +- web_src/less/features/heatmap.less | 63 +++++++++++---------- 11 files changed, 90 insertions(+), 78 deletions(-) rename templates/user/{dashboard => }/heatmap.tmpl (51%) create mode 100644 web_src/js/features/heatmap.js delete mode 100644 web_src/js/features/userheatmap.js diff --git a/routers/user/home.go b/routers/user/home.go index f7f1786b3..779971ca9 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -114,8 +114,14 @@ func Dashboard(ctx *context.Context) { ctx.Data["SearchLimit"] = setting.UI.User.RepoPagingNum // no heatmap access for admins; GetUserHeatmapDataByUser ignores the calling user // so everyone would get the same empty heatmap - ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap && !ctxUser.KeepActivityPrivate - ctx.Data["HeatmapUser"] = ctxUser.Name + if setting.Service.EnableUserHeatmap && !ctxUser.KeepActivityPrivate { + data, err := models.GetUserHeatmapDataByUser(ctxUser) + if err != nil { + ctx.ServerError("GetUserHeatmapDataByUser", err) + return + } + ctx.Data["HeatmapData"] = data + } var err error var mirrors []*models.Repository diff --git a/routers/user/profile.go b/routers/user/profile.go index 8bf5cacc5..36f3d0735 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -94,10 +94,18 @@ func Profile(ctx *context.Context) { ctx.Data["PageIsUserProfile"] = true ctx.Data["Owner"] = ctxUser ctx.Data["OpenIDs"] = openIDs + // no heatmap access for admins; GetUserHeatmapDataByUser ignores the calling user // so everyone would get the same empty heatmap - ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap && !ctxUser.KeepActivityPrivate - ctx.Data["HeatmapUser"] = ctxUser.Name + if setting.Service.EnableUserHeatmap && !ctxUser.KeepActivityPrivate { + data, err := models.GetUserHeatmapDataByUser(ctxUser) + if err != nil { + ctx.ServerError("GetUserHeatmapDataByUser", err) + return + } + ctx.Data["HeatmapData"] = data + } + if len(ctxUser.Description) != 0 { ctx.Data["RenderedDescription"] = string(markdown.Render([]byte(ctxUser.Description), ctx.Repo.RepoLink, map[string]string{"mode": "document"})) } diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 4738b9146..c8e669387 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -36,8 +36,6 @@ SimpleMDE: {{if .RequireSimpleMDE}}true{{else}}false{{end}}, Tribute: {{if .RequireTribute}}true{{else}}false{{end}}, U2F: {{if .RequireU2F}}true{{else}}false{{end}}, - Heatmap: {{if .EnableHeatmap}}true{{else}}false{{end}}, - heatmapUser: {{if .HeatmapUser}}'{{.HeatmapUser}}'{{else}}null{{end}}, NotificationSettings: { MinTimeout: {{NotificationSettings.MinTimeout}}, TimeoutStep: {{NotificationSettings.TimeoutStep}}, diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index 7a4968ebe..dc04d6565 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -5,10 +5,7 @@ {{template "base/alert" .}}
- {{if .EnableHeatmap}} - {{template "user/dashboard/heatmap" .}} -
- {{end}} + {{template "user/heatmap" .}} {{template "user/dashboard/feeds" .}}
{{template "user/dashboard/repolist" .}} diff --git a/templates/user/dashboard/heatmap.tmpl b/templates/user/heatmap.tmpl similarity index 51% rename from templates/user/dashboard/heatmap.tmpl rename to templates/user/heatmap.tmpl index 626c70dd8..a569405d1 100644 --- a/templates/user/dashboard/heatmap.tmpl +++ b/templates/user/heatmap.tmpl @@ -1,7 +1,8 @@ -
- +{{if .HeatmapData}} +
{{.i18n.Tr "user.heatmap.loading"}}
- -
+
+
+{{end}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 3a3192a82..d6b99b386 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -108,10 +108,7 @@

{{.i18n.Tr "user.disabled_public_activity"}}

{{end}} - {{if .EnableHeatmap}} - {{template "user/dashboard/heatmap" .}} -
- {{end}} + {{template "user/heatmap" .}}
{{template "user/dashboard/feeds" .}}
diff --git a/web_src/js/components/ActivityHeatmap.vue b/web_src/js/components/ActivityHeatmap.vue index 1970cb609..943bf704e 100644 --- a/web_src/js/components/ActivityHeatmap.vue +++ b/web_src/js/components/ActivityHeatmap.vue @@ -1,13 +1,9 @@