aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-09-06 00:41:16 +0800
committerGitHub <noreply@github.com>2022-09-05 19:41:16 +0300
commitbc4cce138acf61a1a934098f08c3011126070424 (patch)
treed5ded66f4c1752a5f428974c5343d65fbda04e54
parentb42aaf29ea09b134feb42045c3f17bd6dda7c132 (diff)
downloadgitea-bc4cce138acf61a1a934098f08c3011126070424.tar.gz
gitea-bc4cce138acf61a1a934098f08c3011126070424.zip
Fix delete user missed some comments (#21067)
There is a mistake in the batched delete comments part of DeleteUser which causes some comments to not be deleted The code incorrectly updates the `start` of the limit clause resulting in most comments not being deleted. ```go if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, start).Find(&comments); err != nil { ``` should be: ```go if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, 0).Find(&comments); err != nil { ``` Co-authored-by: zeripath <art27@cantab.net>
-rw-r--r--models/user.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/models/user.go b/models/user.go
index fceb5aabec..68be0d8555 100644
--- a/models/user.go
+++ b/models/user.go
@@ -102,9 +102,9 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
// Delete Comments
const batchSize = 50
- for start := 0; ; start += batchSize {
+ for {
comments := make([]*issues_model.Comment, 0, batchSize)
- if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, start).Find(&comments); err != nil {
+ if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, 0).Find(&comments); err != nil {
return err
}
if len(comments) == 0 {
@@ -202,7 +202,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
// ***** END: ExternalLoginUser *****
if _, err = e.ID(u.ID).Delete(new(user_model.User)); err != nil {
- return fmt.Errorf("Delete: %v", err)
+ return fmt.Errorf("delete: %v", err)
}
return nil