Skip to content

Commit bc4cce1

Browse files
lunnyzeripath
andauthored
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 <[email protected]>
1 parent b42aaf2 commit bc4cce1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

models/user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
102102

103103
// Delete Comments
104104
const batchSize = 50
105-
for start := 0; ; start += batchSize {
105+
for {
106106
comments := make([]*issues_model.Comment, 0, batchSize)
107-
if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, start).Find(&comments); err != nil {
107+
if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, 0).Find(&comments); err != nil {
108108
return err
109109
}
110110
if len(comments) == 0 {
@@ -202,7 +202,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
202202
// ***** END: ExternalLoginUser *****
203203

204204
if _, err = e.ID(u.ID).Delete(new(user_model.User)); err != nil {
205-
return fmt.Errorf("Delete: %v", err)
205+
return fmt.Errorf("delete: %v", err)
206206
}
207207

208208
return nil

0 commit comments

Comments
 (0)