From ded980b6764edea123aa2e212db22a69af1bc9af Mon Sep 17 00:00:00 2001 From: aichy Date: Fri, 23 Dec 2022 14:10:38 +0800 Subject: [PATCH] update captcha --- internal/repo/captcha/captcha.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/internal/repo/captcha/captcha.go b/internal/repo/captcha/captcha.go index 02e8ab8a..bda41d1e 100644 --- a/internal/repo/captcha/captcha.go +++ b/internal/repo/captcha/captcha.go @@ -25,7 +25,7 @@ func NewCaptchaRepo(data *data.Data) action.CaptchaRepo { } func (cr *captchaRepo) SetActionType(ctx context.Context, ip, actionType string, amount int) (err error) { - cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType) + cacheKey := fmt.Sprintf("ActionRecord:%s@", ip) err = cr.data.Cache.SetInt64(ctx, cacheKey, int64(amount), 6*time.Minute) if err != nil { err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() @@ -34,19 +34,16 @@ func (cr *captchaRepo) SetActionType(ctx context.Context, ip, actionType string, } func (cr *captchaRepo) GetActionType(ctx context.Context, ip, actionType string) (amount int, err error) { - //cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType) - //Detects behavior based on ip only cacheKey := fmt.Sprintf("ActionRecord:%s@", ip) res, err := cr.data.Cache.GetInt64(ctx, cacheKey) if err != nil { err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() } - // TODO: cache reflect should return empty when key not found return int(res), nil } func (cr *captchaRepo) DelActionType(ctx context.Context, ip, actionType string) (err error) { - cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType) + cacheKey := fmt.Sprintf("ActionRecord:%s@", ip) err = cr.data.Cache.Del(ctx, cacheKey) if err != nil { err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() @@ -56,7 +53,6 @@ func (cr *captchaRepo) DelActionType(ctx context.Context, ip, actionType string) // SetCaptcha set captcha to cache func (cr *captchaRepo) SetCaptcha(ctx context.Context, key, captcha string) (err error) { - // TODO make cache time to config err = cr.data.Cache.SetString(ctx, key, captcha, 6*time.Minute) if err != nil { err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() @@ -70,6 +66,5 @@ func (cr *captchaRepo) GetCaptcha(ctx context.Context, key string) (captcha stri if err != nil { log.Debug(err) } - // TODO: cache reflect should return empty when key not found return captcha, nil }