A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(votes): set real rank when reach the lowest limit
LinkinStars7c1e88086860
diff --git a/internal/repo/activity/vote_repo.go b/internal/repo/activity/vote_repo.goindex 3c65f4e9..04d56053 100644--- a/internal/repo/activity/vote_repo.go+++ b/internal/repo/activity/vote_repo.go@@ -76,7 +76,7 @@ func (vr *VoteRepo) Vote(ctx context.Context, op *schema.VoteOperationInfo) (errreturn nil, err}- err = vr.setActivityRankToZeroIfUserReachLimit(ctx, session, op, maxDailyRank)+ err = vr.setActivityRankToZeroIfUserReachLimit(ctx, session, op, userInfoMapping, maxDailyRank)if err != nil {return nil, err}@@ -217,16 +217,26 @@ func (vr *VoteRepo) acquireUserInfo(session *xorm.Session, userIDs []string) (ma}func (vr *VoteRepo) setActivityRankToZeroIfUserReachLimit(ctx context.Context, session *xorm.Session,- op *schema.VoteOperationInfo, maxDailyRank int) (err error) {+ op *schema.VoteOperationInfo, userInfoMapping map[string]*entity.User, maxDailyRank int) (err error) {// check if user reach daily rank limitfor _, activity := range op.Activities {- reach, err := vr.userRankRepo.CheckReachLimit(ctx, session, activity.ActivityUserID, maxDailyRank)- if err != nil {- log.Error(err)- return err- }- if reach {- activity.Rank = 0+ if activity.Rank > 0 {+ // check if reach max daily rank+ reach, err := vr.userRankRepo.CheckReachLimit(ctx, session, activity.ActivityUserID, maxDailyRank)+ if err != nil {+ log.Error(err)+ return err+ }+ if reach {+ activity.Rank = 0+ continue+ }+ } else {+ // If user rank is lower than 1 after this action, then user rank will be set to 1 only.+ userCurrentScore := userInfoMapping[activity.ActivityUserID].Rank+ if userCurrentScore+activity.Rank < 1 {+ activity.Rank = 1 - userCurrentScore+ }}}return nil