summaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-01-29 12:33:47 +0800
committerGitHub <noreply@github.com>2021-01-29 05:33:47 +0100
commitf761c82c94f27193bfb6cd0648e11e491eda4880 (patch)
treeae2e2a65c4730bc8e7bce5d82e8a3e1f961d7fdf /modules/context
parentaec8029277cb44d42184ad4e7f891d170f9c5f39 (diff)
downloadgitea-f761c82c94f27193bfb6cd0648e11e491eda4880.tar.gz
gitea-f761c82c94f27193bfb6cd0648e11e491eda4880.zip
Fix load time bug (#14508)
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/context.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/modules/context/context.go b/modules/context/context.go
index adae562c0a..210365f0b1 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -10,6 +10,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
+ "fmt"
"html"
"html/template"
"io"
@@ -182,6 +183,10 @@ func (ctx *Context) RedirectToFirst(location ...string) {
// HTML calls Context.HTML and converts template name to string.
func (ctx *Context) HTML(status int, name base.TplName) {
log.Debug("Template: %s", name)
+ var startTime = time.Now()
+ ctx.Data["TmplLoadTimes"] = func() string {
+ return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
+ }
if err := ctx.Render.HTML(ctx.Resp, status, string(name), ctx.Data); err != nil {
ctx.ServerError("Render failed", err)
}
@@ -190,6 +195,10 @@ func (ctx *Context) HTML(status int, name base.TplName) {
// HTMLString render content to a string but not http.ResponseWriter
func (ctx *Context) HTMLString(name string, data interface{}) (string, error) {
var buf strings.Builder
+ var startTime = time.Now()
+ ctx.Data["TmplLoadTimes"] = func() string {
+ return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
+ }
err := ctx.Render.HTML(&buf, 200, string(name), data)
return buf.String(), err
}
@@ -547,10 +556,7 @@ func Contexter() func(next http.Handler) http.Handler {
Data: map[string]interface{}{
"CurrentURL": setting.AppSubURL + req.URL.RequestURI(),
"PageStartTime": startTime,
- "TmplLoadTimes": func() string {
- return time.Since(startTime).String()
- },
- "Link": link,
+ "Link": link,
},
}