This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch fix/load-plugin-config in repository https://gitbox.apache.org/repos/asf/answer.git
commit 10ee8c80fb713a04a077dcf06435fd220261a60d Author: LinkinStars <[email protected]> AuthorDate: Thu Jan 29 11:15:08 2026 +0800 feat: add GetConfigByKeyFromDB method to retrieve config directly --- internal/repo/config/config_repo.go | 12 ++++++++++++ internal/service/config/config_service.go | 10 ++++++++++ internal/service/plugin_common/plugin_common_service.go | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/repo/config/config_repo.go b/internal/repo/config/config_repo.go index 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 exists oldConfig := &entity.Config{Key: key} diff --git a/internal/service/config/config_service.go b/internal/service/config/config_service.go index 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 st return 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 value func (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.go index 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 {
