Skip to content

Commit e4a7736

Browse files
committed
feat(notification): add notification limit
1 parent 8a037f0 commit e4a7736

15 files changed

Lines changed: 92 additions & 49 deletions

File tree

cmd/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ require (
2929
github.com/ory/dockertest/v3 v3.9.1
3030
github.com/robfig/cron/v3 v3.0.1
3131
github.com/scottleedavis/go-exif-remove v0.0.0-20230314195146-7e059d593405
32-
github.com/segmentfault/pacman v1.0.5-0.20230822075009-309985fb8700
33-
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20230822075009-309985fb8700
32+
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f
33+
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20230822083413-c0075a2d401f
3434
github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20221018072427-a15dd1434e05
3535
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093754-b76aef1c1150
3636
github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20221018072427-a15dd1434e05

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZw
8989
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
9090
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
9191
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
92+
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
9293
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
9394
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
9495
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
@@ -644,8 +645,12 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
644645
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
645646
github.com/segmentfault/pacman v1.0.5-0.20230822075009-309985fb8700 h1:VqxiuNGQg86GEKxnzmJegZR2Ufr7EVXo68mdKaf+/MQ=
646647
github.com/segmentfault/pacman v1.0.5-0.20230822075009-309985fb8700/go.mod h1:5lNp5REd8QMThmBUvR3Fi9Y3AsOB4GRq7soCB4QLqOs=
648+
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f h1:9f2Bjf6bdMvNyUop32wAGJCdp+Jdm/d6nKBYvFvkRo0=
649+
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f/go.mod h1:5lNp5REd8QMThmBUvR3Fi9Y3AsOB4GRq7soCB4QLqOs=
647650
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20230822075009-309985fb8700 h1:VZpexPTcr7sOxxYUGa/9cneyCESfisAhCNbaEuTpcwI=
648651
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20230822075009-309985fb8700/go.mod h1:rmf1TCwz67dyM+AmTwSd1BxTo2AOYHj262lP93bOZbs=
652+
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20230822083413-c0075a2d401f h1:1KHe0uN6p798E7XJZPhZkgm/hXk5CTjisCvFMqaZSKI=
653+
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20230822083413-c0075a2d401f/go.mod h1:rmf1TCwz67dyM+AmTwSd1BxTo2AOYHj262lP93bOZbs=
649654
github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20221018072427-a15dd1434e05 h1:BlqTgc3/MYKG6vMI2MI+6o+7P4Gy5PXlawu185wPXAk=
650655
github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20221018072427-a15dd1434e05/go.mod h1:prPjFam7MyZ5b3S9dcDOt2tMPz6kf7C9c243s9zSwPY=
651656
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093754-b76aef1c1150 h1:OEuW1D7RGDE0CZDr0oGMw9Eiq7fAbD9C4WMrvSixamk=
@@ -774,6 +779,7 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
774779
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
775780
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
776781
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
782+
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
777783
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
778784
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
779785
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=

internal/base/constant/cache_key.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ package constant
33
import "time"
44

55
const (
6-
UserStatusChangedCacheKey = "answer:user:status:"
7-
UserStatusChangedCacheTime = 7 * 24 * time.Hour
8-
UserTokenCacheKey = "answer:user:token:"
9-
UserTokenCacheTime = 7 * 24 * time.Hour
10-
AdminTokenCacheKey = "answer:admin:token:"
11-
AdminTokenCacheTime = 7 * 24 * time.Hour
12-
UserTokenMappingCacheKey = "answer:user-token:mapping:"
13-
SiteInfoCacheKey = "answer:site-info:"
14-
SiteInfoCacheTime = 1 * time.Hour
15-
ConfigID2KEYCacheKeyPrefix = "answer:config:id:"
16-
ConfigKEY2ContentCacheKeyPrefix = "answer:config:key:"
17-
ConnectorUserExternalInfoCacheKey = "answer:connector:"
18-
ConnectorUserExternalInfoCacheTime = 10 * time.Minute
19-
SiteMapQuestionCacheKeyPrefix = "answer:sitemap:question:%d"
20-
SiteMapQuestionCacheTime = time.Hour
21-
SitemapMaxSize = 50000
6+
UserStatusChangedCacheKey = "answer:user:status:"
7+
UserStatusChangedCacheTime = 7 * 24 * time.Hour
8+
UserTokenCacheKey = "answer:user:token:"
9+
UserTokenCacheTime = 7 * 24 * time.Hour
10+
AdminTokenCacheKey = "answer:admin:token:"
11+
AdminTokenCacheTime = 7 * 24 * time.Hour
12+
UserTokenMappingCacheKey = "answer:user-token:mapping:"
13+
SiteInfoCacheKey = "answer:site-info:"
14+
SiteInfoCacheTime = 1 * time.Hour
15+
ConfigID2KEYCacheKeyPrefix = "answer:config:id:"
16+
ConfigKEY2ContentCacheKeyPrefix = "answer:config:key:"
17+
ConnectorUserExternalInfoCacheKey = "answer:connector:"
18+
ConnectorUserExternalInfoCacheTime = 10 * time.Minute
19+
SiteMapQuestionCacheKeyPrefix = "answer:sitemap:question:%d"
20+
SiteMapQuestionCacheTime = time.Hour
21+
SitemapMaxSize = 50000
22+
NewQuestionNotificationLimitCacheKeyPrefix = "answer:new-question-notification-limit:"
23+
NewQuestionNotificationLimitCacheTime = 7 * 24 * time.Hour
24+
NewQuestionNotificationLimitMax = 50
2225
)

internal/migrations/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var migrations = []Migration{
7171
NewMigration("v1.1.0-beta.2", "update question post time", updateQuestionPostTime, true),
7272
NewMigration("v1.1.0", "add gravatar base url", updateCount, true),
7373
NewMigration("v1.1.1", "update the length of revision content", updateTheLengthOfRevisionContent, false),
74-
NewMigration("v1.1.2", "add notification config", addNoticeConfig, false),
74+
NewMigration("v1.1.2", "add notification config", addNoticeConfig, true),
7575
}
7676

7777
func GetMigrations() []Migration {

internal/repo/auth/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ func (ar *authRepo) GetUserCacheInfo(ctx context.Context, accessToken string) (u
3131
if err != nil {
3232
return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
3333
}
34-
userInfo = &entity.UserCacheInfo{}
3534
if !exist {
3635
return nil, nil
3736
}
37+
userInfo = &entity.UserCacheInfo{}
3838
_ = json.Unmarshal([]byte(userInfoCache), userInfo)
3939
return userInfo, nil
4040
}

internal/repo/captcha/captcha.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ func (cr *captchaRepo) GetActionType(ctx context.Context, unit, actionType strin
5050
if err != nil {
5151
return nil, err
5252
}
53-
actionInfo = &entity.ActionRecordInfo{}
54-
if exist {
55-
_ = json.Unmarshal([]byte(res), actionInfo)
53+
if !exist {
54+
return nil, nil
5655
}
56+
actionInfo = &entity.ActionRecordInfo{}
57+
_ = json.Unmarshal([]byte(res), actionInfo)
5758
return actionInfo, nil
5859
}
5960

internal/repo/site_info/siteinfo_repo.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (sr *siteInfoRepo) GetByType(ctx context.Context, siteType string) (siteInf
5353
exist, err = sr.data.DB.Context(ctx).Where(builder.Eq{"type": siteType}).Get(siteInfo)
5454
if err != nil {
5555
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
56+
return nil, false, err
5657
}
5758
if exist {
5859
sr.setCache(ctx, siteType, siteInfo)
@@ -65,10 +66,11 @@ func (sr *siteInfoRepo) getCache(ctx context.Context, siteType string) (siteInfo
6566
if err != nil {
6667
return nil
6768
}
68-
siteInfo = &entity.SiteInfo{}
69-
if exist {
70-
_ = json.Unmarshal([]byte(siteInfoCache), siteInfo)
69+
if !exist {
70+
return nil
7171
}
72+
siteInfo = &entity.SiteInfo{}
73+
_ = json.Unmarshal([]byte(siteInfoCache), siteInfo)
7274
return siteInfo
7375
}
7476

internal/repo/user_external_login/user_external_login_repo.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ func (ur *userExternalLoginRepo) GetCacheUserExternalLoginInfo(
8989
if err != nil {
9090
return info, err
9191
}
92-
info = &schema.ExternalLoginUserInfoCache{}
93-
if exist {
94-
_ = json.Unmarshal([]byte(res), &info)
92+
if !exist {
93+
return nil, nil
9594
}
95+
info = &schema.ExternalLoginUserInfoCache{}
96+
_ = json.Unmarshal([]byte(res), &info)
9697
return info, nil
9798
}

internal/service/action/captcha_service.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,20 @@ func (cs *CaptchaService) ActionRecordVerifyCaptcha(
111111
}
112112

113113
func (cs *CaptchaService) ActionRecordAdd(ctx context.Context, actionType string, unit string) (int, error) {
114-
var err error
115-
info, cahceErr := cs.captchaRepo.GetActionType(ctx, unit, actionType)
116-
if cahceErr != nil {
114+
info, err := cs.captchaRepo.GetActionType(ctx, unit, actionType)
115+
if err != nil {
117116
log.Error(err)
117+
return 0, err
118+
}
119+
amount := 1
120+
if info != nil {
121+
amount = info.Num + 1
118122
}
119-
info.Num++
120-
err = cs.captchaRepo.SetActionType(ctx, unit, actionType, "", info.Num)
123+
err = cs.captchaRepo.SetActionType(ctx, unit, actionType, "", amount)
121124
if err != nil {
122125
return 0, err
123126
}
124-
return info.Num, nil
127+
return amount, nil
125128
}
126129

127130
func (cs *CaptchaService) ActionRecordDel(ctx context.Context, actionType string, unit string) {

0 commit comments

Comments
 (0)