mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-07-13 04:58:46 +00:00
fix(ui): in the admin config panel do not report a cache taking more than 100 microseconds as slow (#13256)
There is no absolute threshold to decide a cache is slow. Report the time it took to run the test and let the user decide if this is too slow or not. Closes forgejo/forgejo#5846 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13256 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org> Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
parent
327cbada8a
commit
8ee7e7c32b
6 changed files with 16 additions and 14 deletions
1
modules/cache/cache.go
vendored
1
modules/cache/cache.go
vendored
|
|
@ -49,7 +49,6 @@ func Init() error {
|
|||
|
||||
const (
|
||||
testCacheKey = "DefaultCache.TestKey"
|
||||
SlowCacheThreshold = 100 * time.Microsecond
|
||||
)
|
||||
|
||||
func Test() (time.Duration, error) {
|
||||
|
|
|
|||
|
|
@ -3144,7 +3144,6 @@ config.cache_item_ttl = Cache item TTL
|
|||
|
||||
config.cache_test = Test Cache
|
||||
config.cache_test_failed = Failed to probe the cache: %v.
|
||||
config.cache_test_slow = Cache test successful, but response is slow: %s.
|
||||
config.cache_test_succeeded = Cache test successful, got a response in %s.
|
||||
|
||||
config.session_config = Session configuration
|
||||
|
|
|
|||
|
|
@ -233,11 +233,9 @@ func SelfCheck(ctx *context.Context) {
|
|||
ctx.Data["DatabaseCheckHasProblems"] = hasProblem
|
||||
}
|
||||
|
||||
elapsed, err := cache.Test()
|
||||
_, err = cache.Test()
|
||||
if err != nil {
|
||||
ctx.Data["CacheError"] = err
|
||||
} else if elapsed > cache.SlowCacheThreshold {
|
||||
ctx.Data["CacheSlow"] = fmt.Sprint(elapsed)
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, tplSelfCheck)
|
||||
|
|
|
|||
|
|
@ -49,13 +49,9 @@ func TestCache(ctx *context.Context) {
|
|||
elapsed, err := cache.Test()
|
||||
if err != nil {
|
||||
ctx.Flash.Error(ctx.Tr("admin.config.cache_test_failed", err))
|
||||
} else {
|
||||
if elapsed > cache.SlowCacheThreshold {
|
||||
ctx.Flash.Warning(ctx.Tr("admin.config.cache_test_slow", elapsed))
|
||||
} else {
|
||||
ctx.Flash.Info(ctx.Tr("admin.config.cache_test_succeeded", elapsed))
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubURL + "/admin/config")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,9 +32,6 @@
|
|||
{{if .CacheError}}
|
||||
<div class="ui red message">{{ctx.Locale.Tr "admin.config.cache_test_failed" .CacheError}}</div>
|
||||
{{end}}
|
||||
{{if .CacheSlow}}
|
||||
<div class="ui warning message">{{ctx.Locale.Tr "admin.config.cache_test_slow" .CacheSlow}}</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"forgejo.org/modules/test"
|
||||
app_context "forgejo.org/services/context"
|
||||
"forgejo.org/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -21,3 +22,15 @@ func TestAdminConfig(t *testing.T) {
|
|||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
assert.True(t, test.IsNormalPageCompleted(resp.Body.String()))
|
||||
}
|
||||
|
||||
func TestAdminConfigCacheTest(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, "user1")
|
||||
req := NewRequest(t, "POST", "/admin/config/test_cache")
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
flashCookie := session.GetCookie(app_context.CookieNameFlash)
|
||||
assert.NotNil(t, flashCookie)
|
||||
assert.Contains(t, flashCookie.Value, "info%3DCache%2Btest%2Bsuccessful%252C%2Bgot%2Ba%2Bresponse")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue