Skip to content
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

Fix load time bug #14508

Merged
merged 4 commits into from
Jan 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions modules/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"html"
"html/template"
"io"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
},
}

Expand Down