Add: ClearServerAllCache Func
This commit is contained in:
parent
829d5f3ffd
commit
2605d22f8e
@ -48,5 +48,9 @@ func (l *DeleteUserSubscribeLogic) DeleteUserSubscribe(req *types.DeleteUserSubs
|
|||||||
l.Errorw("failed to clear subscribe cache", logger.Field("error", err.Error()), logger.Field("subscribeId", userSubscribe.SubscribeId))
|
l.Errorw("failed to clear subscribe cache", logger.Field("error", err.Error()), logger.Field("subscribeId", userSubscribe.SubscribeId))
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "failed to clear subscribe cache: %v", err.Error())
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "failed to clear subscribe cache: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
if err = l.svcCtx.NodeModel.ClearServerAllCache(l.ctx); err != nil {
|
||||||
|
l.Errorf("ClearServerAllCache error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "failed to clear server cache: %v", err.Error())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,5 +69,10 @@ func (l *UpdateUserSubscribeLogic) UpdateUserSubscribe(req *types.UpdateUserSubs
|
|||||||
l.Errorw("failed to clear subscribe cache", logger.Field("error", err.Error()), logger.Field("subscribeId", userSub.SubscribeId))
|
l.Errorw("failed to clear subscribe cache", logger.Field("error", err.Error()), logger.Field("subscribeId", userSub.SubscribeId))
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "failed to clear subscribe cache: %v", err.Error())
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "failed to clear subscribe cache: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = l.svcCtx.NodeModel.ClearServerAllCache(l.ctx); err != nil {
|
||||||
|
l.Errorf("ClearServerAllCache error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "failed to clear server cache: %v", err.Error())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -301,5 +301,8 @@ func (l *DeviceLoginLogic) activeTrial(userId int64, db *gorm.DB) error {
|
|||||||
logger.Field("traffic", sub.Traffic),
|
logger.Field("traffic", sub.Traffic),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if clearErr := l.svcCtx.NodeModel.ClearServerAllCache(l.ctx); clearErr != nil {
|
||||||
|
l.Errorf("ClearServerAllCache error: %v", clearErr.Error())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -245,5 +245,12 @@ func (l *TelephoneUserRegisterLogic) activeTrial(uid int64) error {
|
|||||||
UUID: uuidx.NewUUID().String(),
|
UUID: uuidx.NewUUID().String(),
|
||||||
Status: 1,
|
Status: 1,
|
||||||
}
|
}
|
||||||
return l.svcCtx.UserModel.InsertSubscribe(l.ctx, userSub)
|
err = l.svcCtx.UserModel.InsertSubscribe(l.ctx, userSub)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if clearErr := l.svcCtx.NodeModel.ClearServerAllCache(l.ctx); clearErr != nil {
|
||||||
|
l.Errorf("ClearServerAllCache error: %v", clearErr.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -231,5 +231,12 @@ func (l *UserRegisterLogic) activeTrial(uid int64) error {
|
|||||||
UUID: uuidx.NewUUID().String(),
|
UUID: uuidx.NewUUID().String(),
|
||||||
Status: 1,
|
Status: 1,
|
||||||
}
|
}
|
||||||
return l.svcCtx.UserModel.InsertSubscribe(l.ctx, userSub)
|
err = l.svcCtx.UserModel.InsertSubscribe(l.ctx, userSub)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if clearErr := l.svcCtx.NodeModel.ClearServerAllCache(l.ctx); clearErr != nil {
|
||||||
|
l.Errorf("ClearServerAllCache error: %v", clearErr.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,6 +83,9 @@ func (l *ResetUserSubscribeTokenLogic) ResetUserSubscribeToken(req *types.ResetU
|
|||||||
l.Errorw("ClearSubscribeCache failed", logger.Field("error", err.Error()), logger.Field("subscribeId", userSub.SubscribeId))
|
l.Errorw("ClearSubscribeCache failed", logger.Field("error", err.Error()), logger.Field("subscribeId", userSub.SubscribeId))
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "ClearSubscribeCache failed: %v", err.Error())
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "ClearSubscribeCache failed: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
if err = l.svcCtx.NodeModel.ClearServerAllCache(l.ctx); err != nil {
|
||||||
|
l.Errorf("ClearServerAllCache error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "failed to clear server cache: %v", err.Error())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ type customServerLogicModel interface {
|
|||||||
FilterServerList(ctx context.Context, params *FilterParams) (int64, []*Server, error)
|
FilterServerList(ctx context.Context, params *FilterParams) (int64, []*Server, error)
|
||||||
FilterNodeList(ctx context.Context, params *FilterNodeParams) (int64, []*Node, error)
|
FilterNodeList(ctx context.Context, params *FilterNodeParams) (int64, []*Node, error)
|
||||||
ClearNodeCache(ctx context.Context, params *FilterNodeParams) error
|
ClearNodeCache(ctx context.Context, params *FilterNodeParams) error
|
||||||
|
ClearServerAllCache(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -171,6 +172,30 @@ func (m *customServerModel) ClearServerCache(ctx context.Context, serverId int64
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *customServerModel) ClearServerAllCache(ctx context.Context) error {
|
||||||
|
var cursor uint64
|
||||||
|
var keys []string
|
||||||
|
prefix := ServerConfigCacheKey + "*"
|
||||||
|
for {
|
||||||
|
scanKeys, newCursor, err := m.Cache.Scan(ctx, cursor, prefix, 999).Result()
|
||||||
|
if err != nil {
|
||||||
|
m.Logger.Error(ctx, fmt.Sprintf("ClearServerAllCache err:%v", err))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
m.Logger.Info(ctx, fmt.Sprintf("ClearServerAllCache query keys:%v", scanKeys))
|
||||||
|
keys = append(keys, scanKeys...)
|
||||||
|
cursor = newCursor
|
||||||
|
if cursor == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(keys) > 0 {
|
||||||
|
m.Logger.Info(ctx, fmt.Sprintf("ClearServerAllCache keys:%v", keys))
|
||||||
|
return m.Cache.Del(ctx, keys...).Err()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// InSet 支持多值 OR 查询
|
// InSet 支持多值 OR 查询
|
||||||
func InSet(field string, values []string) func(db *gorm.DB) *gorm.DB {
|
func InSet(field string, values []string) func(db *gorm.DB) *gorm.DB {
|
||||||
return func(db *gorm.DB) *gorm.DB {
|
return func(db *gorm.DB) *gorm.DB {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user