A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: add GetConfigByKeyFromDB method to retrieve config directly
LinkinStarsb522a168e34e
diff --git a/internal/repo/config/config_repo.go b/internal/repo/config/config_repo.goindex 3708aa3e..bf0035cb 100644--- a/internal/repo/config/config_repo.go+++ b/internal/repo/config/config_repo.go@@ -99,6 +99,18 @@ func (cr configRepo) GetConfigByKey(ctx context.Context, key string) (c *entity.return c, nil}+func (cr configRepo) GetConfigByKeyFromDB(ctx context.Context, key string) (c *entity.Config, err error) {+ c = &entity.Config{Key: key}+ exist, err := cr.data.DB.Context(ctx).Get(c)+ if err != nil {+ return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ }+ if !exist {+ return nil, fmt.Errorf("config not found by key: %s", key)+ }+ return c, nil+}+func (cr configRepo) UpdateConfig(ctx context.Context, key string, value string) (err error) {// check if key existsoldConfig := &entity.Config{Key: key}diff --git a/internal/service/config/config_service.go b/internal/service/config/config_service.goindex 63aea221..0848d604 100644--- a/internal/service/config/config_service.go+++ b/internal/service/config/config_service.go@@ -31,6 +31,7 @@ import (type ConfigRepo interface {GetConfigByID(ctx context.Context, id int) (c *entity.Config, err error)GetConfigByKey(ctx context.Context, key string) (c *entity.Config, err error)+ GetConfigByKeyFromDB(ctx context.Context, key string) (c *entity.Config, err error)UpdateConfig(ctx context.Context, key, value string) (err error)}@@ -64,6 +65,15 @@ func (cs *ConfigService) GetStringValue(ctx context.Context, key string) (val streturn cf.Value, nil}+// GetStringValueFromDB gets config string value directly from DB, bypassing cache.+func (cs *ConfigService) GetStringValueFromDB(ctx context.Context, key string) (val string, err error) {+ cf, err := cs.configRepo.GetConfigByKeyFromDB(ctx, key)+ if err != nil {+ return "", err+ }+ return cf.Value, nil+}+// GetArrayStringValue get config array string valuefunc (cs *ConfigService) GetArrayStringValue(ctx context.Context, key string) (val []string, err error) {cf, err := cs.configRepo.GetConfigByKey(ctx, key)diff --git a/internal/service/plugin_common/plugin_common_service.go b/internal/service/plugin_common/plugin_common_service.goindex 7d39a5aa..eb46b5ac 100644--- a/internal/service/plugin_common/plugin_common_service.go+++ b/internal/service/plugin_common/plugin_common_service.go@@ -144,7 +144,7 @@ func (ps *PluginCommonService) initPluginData() {})// init plugin status- pluginStatus, err := ps.configService.GetStringValue(context.TODO(), constant.PluginStatus)+ pluginStatus, err := ps.configService.GetStringValueFromDB(context.TODO(), constant.PluginStatus)if err != nil {log.Error(err)} else {