mirror of https://github.com/go-gitea/gitea.git
Fix load time bug (#14508)
This commit is contained in:
parent
aec8029277
commit
f761c82c94
|
@ -10,6 +10,7 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
@ -182,6 +183,10 @@ func (ctx *Context) RedirectToFirst(location ...string) {
|
||||||
// HTML calls Context.HTML and converts template name to string.
|
// HTML calls Context.HTML and converts template name to string.
|
||||||
func (ctx *Context) HTML(status int, name base.TplName) {
|
func (ctx *Context) HTML(status int, name base.TplName) {
|
||||||
log.Debug("Template: %s", name)
|
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 {
|
if err := ctx.Render.HTML(ctx.Resp, status, string(name), ctx.Data); err != nil {
|
||||||
ctx.ServerError("Render failed", err)
|
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
|
// HTMLString render content to a string but not http.ResponseWriter
|
||||||
func (ctx *Context) HTMLString(name string, data interface{}) (string, error) {
|
func (ctx *Context) HTMLString(name string, data interface{}) (string, error) {
|
||||||
var buf strings.Builder
|
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)
|
err := ctx.Render.HTML(&buf, 200, string(name), data)
|
||||||
return buf.String(), err
|
return buf.String(), err
|
||||||
}
|
}
|
||||||
|
@ -547,9 +556,6 @@ func Contexter() func(next http.Handler) http.Handler {
|
||||||
Data: map[string]interface{}{
|
Data: map[string]interface{}{
|
||||||
"CurrentURL": setting.AppSubURL + req.URL.RequestURI(),
|
"CurrentURL": setting.AppSubURL + req.URL.RequestURI(),
|
||||||
"PageStartTime": startTime,
|
"PageStartTime": startTime,
|
||||||
"TmplLoadTimes": func() string {
|
|
||||||
return time.Since(startTime).String()
|
|
||||||
},
|
|
||||||
"Link": link,
|
"Link": link,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue