]> source.dussan.org Git - gitea.git/commitdiff
Use a variable but a function for IsProd because of a slight performance increment...
authorLunny Xiao <xiaolunwen@gmail.com>
Wed, 20 Oct 2021 14:37:19 +0000 (22:37 +0800)
committerGitHub <noreply@github.com>
Wed, 20 Oct 2021 14:37:19 +0000 (16:37 +0200)
12 files changed:
cmd/serv.go
models/db/engine.go
modules/context/api.go
modules/context/context.go
modules/httpcache/httpcache.go
modules/setting/setting.go
modules/templates/base.go
routers/common/middleware.go
routers/install/routes.go
routers/web/base.go
routers/web/web.go
services/auth/sspi_windows.go

index 2173a3a38b8586446b8c91fb12ccb124d14d5a8d..13c27f1ac05dd4d31c4325428d0738f05e4e31ee 100644 (file)
@@ -80,7 +80,7 @@ func fail(userMessage, logMessage string, args ...interface{}) error {
        fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
 
        if len(logMessage) > 0 {
-               if !setting.IsProd() {
+               if !setting.IsProd {
                        fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
                }
        }
index 256eb2f3fc725e65577ced90e7da2d751b408ce2..78b4ac22dde8524733ca1964d885e391e9869495 100755 (executable)
@@ -136,8 +136,8 @@ func NewTestEngine() (err error) {
        }
 
        x.SetMapper(names.GonicMapper{})
-       x.SetLogger(NewXORMLogger(!setting.IsProd()))
-       x.ShowSQL(!setting.IsProd())
+       x.SetLogger(NewXORMLogger(!setting.IsProd))
+       x.ShowSQL(!setting.IsProd)
        return syncTables()
 }
 
index e5216d911f8a6cfdac8fec747307a0029e48dc07..c978835af87494c0f02dad5bee0bc58879d7c23f 100644 (file)
@@ -95,7 +95,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
        if status == http.StatusInternalServerError {
                log.ErrorWithSkip(1, "%s: %s", title, message)
 
-               if setting.IsProd() && !(ctx.User != nil && ctx.User.IsAdmin) {
+               if setting.IsProd && !(ctx.User != nil && ctx.User.IsAdmin) {
                        message = ""
                }
        }
@@ -112,7 +112,7 @@ func (ctx *APIContext) InternalServerError(err error) {
        log.ErrorWithSkip(1, "InternalServerError: %v", err)
 
        var message string
-       if !setting.IsProd() || (ctx.User != nil && ctx.User.IsAdmin) {
+       if !setting.IsProd || (ctx.User != nil && ctx.User.IsAdmin) {
                message = err.Error()
        }
 
index 0a603cced5f5367a22a71dc45981a56e96b738a6..383a69ad6332fe20d4a6308322726865013f5e74 100644 (file)
@@ -225,7 +225,7 @@ func (ctx *Context) NotFound(title string, err error) {
 func (ctx *Context) notFoundInternal(title string, err error) {
        if err != nil {
                log.ErrorWithSkip(2, "%s: %v", title, err)
-               if !setting.IsProd() {
+               if !setting.IsProd {
                        ctx.Data["ErrorMsg"] = err
                }
        }
@@ -261,7 +261,7 @@ func (ctx *Context) ServerError(title string, err error) {
 func (ctx *Context) serverErrorInternal(title string, err error) {
        if err != nil {
                log.ErrorWithSkip(2, "%s: %v", title, err)
-               if !setting.IsProd() {
+               if !setting.IsProd {
                        ctx.Data["ErrorMsg"] = err
                }
        }
@@ -645,7 +645,7 @@ func Contexter() func(next http.Handler) http.Handler {
                                        "CurrentURL":    setting.AppSubURL + req.URL.RequestURI(),
                                        "PageStartTime": startTime,
                                        "Link":          link,
-                                       "IsProd":        setting.IsProd(),
+                                       "IsProd":        setting.IsProd,
                                },
                        }
                        // PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules
index 35d4e6dfd82e857b54da553fdf1e919814769679..11b63148d9d74fd8b70f6cfc4ddaa3912768ed04 100644 (file)
@@ -18,7 +18,7 @@ import (
 
 // AddCacheControlToHeader adds suitable cache-control headers to response
 func AddCacheControlToHeader(h http.Header, d time.Duration) {
-       if setting.IsProd() {
+       if setting.IsProd {
                h.Set("Cache-Control", "private, max-age="+strconv.Itoa(int(d.Seconds())))
        } else {
                h.Set("Cache-Control", "no-store")
index 2133184cfc40d2de7ea340a01d4da9606320f221..a1ac090e46073642897a8fcfc06677c607db59a0 100644 (file)
@@ -419,17 +419,13 @@ var (
        PIDFile       = "/run/gitea.pid"
        WritePIDFile  bool
        RunMode       string
+       IsProd        bool
        RunUser       string
        IsWindows     bool
        HasRobotsTxt  bool
        InternalToken string // internal access token
 )
 
-// IsProd if it's a production mode
-func IsProd() bool {
-       return strings.EqualFold(RunMode, "prod")
-}
-
 func getAppPath() (string, error) {
        var appPath string
        var err error
@@ -906,6 +902,7 @@ func NewContext() {
        // Please don't use root as a bandaid to "fix" something that is broken, instead the broken thing should instead be fixed properly.
        unsafeAllowRunAsRoot := Cfg.Section("").Key("I_AM_BEING_UNSAFE_RUNNING_AS_ROOT").MustBool(false)
        RunMode = Cfg.Section("").Key("RUN_MODE").MustString("prod")
+       IsProd = strings.EqualFold(RunMode, "prod")
        // Does not check run user when the install lock is off.
        if InstallLock {
                currentUser, match := IsRunUserMatchCurrentUser(RunUser)
index cb83143bd3424894384fdf6cb52cab8713a7ca0b..f753bfbe4ea40798b4c6a83e8dc47bf04b78070a 100644 (file)
@@ -91,7 +91,7 @@ func HTMLRenderer() *render.Render {
                Funcs:                     NewFuncMap(),
                Asset:                     GetAsset,
                AssetNames:                GetAssetNames,
-               IsDevelopment:             !setting.IsProd(),
+               IsDevelopment:             !setting.IsProd,
                DisableHTTPErrorRendering: true,
        })
 }
index 1d96522dd9d1933b3a62ff04538ab416b08aa41a..7c5c72f5cc38afb724e99977ae3c7eebea8837fa 100644 (file)
@@ -62,7 +62,7 @@ func Middlewares() []func(http.Handler) http.Handler {
                                if err := recover(); err != nil {
                                        combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2)))
                                        log.Error("%v", combinedErr)
-                                       if setting.IsProd() {
+                                       if setting.IsProd {
                                                http.Error(resp, http.StatusText(500), 500)
                                        } else {
                                                http.Error(resp, combinedErr, 500)
index e9aca85d8edd6d3bd0b6aacab5c5d4c2ef03480a..ad0003a9e8e341ccd3095d1e6e5359b66ddd1911 100644 (file)
@@ -40,7 +40,7 @@ func installRecovery() func(next http.Handler) http.Handler {
                                        if err := recover(); err != nil {
                                                combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2)))
                                                log.Error(combinedErr)
-                                               if setting.IsProd() {
+                                               if setting.IsProd {
                                                        http.Error(w, http.StatusText(500), 500)
                                                } else {
                                                        http.Error(w, combinedErr, 500)
@@ -63,7 +63,7 @@ func installRecovery() func(next http.Handler) http.Handler {
 
                                        w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
 
-                                       if !setting.IsProd() {
+                                       if !setting.IsProd {
                                                store["ErrorMsg"] = combinedErr
                                        }
                                        err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store))
index f50c5229b1d2351a104786a20e5d4ee88161e57d..16d3192da21dc3f6afbe448c20e913812758bbc8 100644 (file)
@@ -131,7 +131,7 @@ func Recovery() func(next http.Handler) http.Handler {
 
                                        sessionStore := session.GetSession(req)
                                        if sessionStore == nil {
-                                               if setting.IsProd() {
+                                               if setting.IsProd {
                                                        http.Error(w, http.StatusText(500), 500)
                                                } else {
                                                        http.Error(w, combinedErr, 500)
@@ -164,7 +164,7 @@ func Recovery() func(next http.Handler) http.Handler {
 
                                        w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
 
-                                       if !setting.IsProd() {
+                                       if !setting.IsProd {
                                                store["ErrorMsg"] = combinedErr
                                        }
                                        err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store))
index caec0676714c4e1ba3b70d92fb133ddda9233cc5..88565d6d855636942fc1a69c421939de3341fe16 100644 (file)
@@ -477,7 +477,7 @@ func RegisterRoutes(m *web.Route) {
                m.Post("/action/{action}", user.Action)
        }, reqSignIn)
 
-       if !setting.IsProd() {
+       if !setting.IsProd {
                m.Get("/template/*", dev.TemplatePreview)
        }
 
index 346e9439884f95a219b827724d1c297d6f3ee114..821a3df459c328caf474846370f9789f9afd5f47 100644 (file)
@@ -64,7 +64,7 @@ func (s *SSPI) Init() error {
                Funcs:         templates.NewFuncMap(),
                Asset:         templates.GetAsset,
                AssetNames:    templates.GetAssetNames,
-               IsDevelopment: !setting.IsProd(),
+               IsDevelopment: !setting.IsProd,
        })
        return nil
 }