Enable db config cache explicitly

previous config is not cached because it is initialized when cache is not ready

Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
stonezdj 2021-11-04 15:26:38 +08:00
parent b95b3fd84b
commit 162381de56
2 changed files with 13 additions and 0 deletions

View File

@ -54,6 +54,7 @@ import (
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
tracelib "github.com/goharbor/harbor/src/lib/trace" tracelib "github.com/goharbor/harbor/src/lib/trace"
"github.com/goharbor/harbor/src/migration" "github.com/goharbor/harbor/src/migration"
dbCfg "github.com/goharbor/harbor/src/pkg/config/db"
_ "github.com/goharbor/harbor/src/pkg/config/inmemory" _ "github.com/goharbor/harbor/src/pkg/config/inmemory"
"github.com/goharbor/harbor/src/pkg/notification" "github.com/goharbor/harbor/src/pkg/notification"
_ "github.com/goharbor/harbor/src/pkg/notifier/topic" _ "github.com/goharbor/harbor/src/pkg/notifier/topic"
@ -176,6 +177,9 @@ func main() {
if err := cache.Initialize(u.Scheme, redisURL); err != nil { if err := cache.Initialize(u.Scheme, redisURL); err != nil {
log.Fatalf("failed to initialize cache: %v", err) log.Fatalf("failed to initialize cache: %v", err)
} }
// when config/db init function is called, the cache is not ready,
// enable config cache explicitly when the cache is ready
dbCfg.EnableConfigCache()
} }
beego.AddTemplateExt("htm") beego.AddTemplateExt("htm")

View File

@ -44,3 +44,12 @@ func NewDBCfgManager() *config.CfgManager {
manager.LoadSystemConfigFromEnv() manager.LoadSystemConfigFromEnv()
return manager return manager
} }
// EnableConfigCache ...
func EnableConfigCache() {
if cache.Default() == nil {
log.Error("failed to enable config cache, cache is not ready.")
return
}
libCfg.Register(common.DBCfgManager, NewDBCfgManager())
}