Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/repo/config/config_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
10 changes: 10 additions & 0 deletions internal/service/config/config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/plugin_common/plugin_common_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading