-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid WHERE IN
for comment migration query
#28500
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1160,22 +1160,36 @@ func DeleteComment(ctx context.Context, comment *Comment) error { | |
|
||
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id | ||
func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error { | ||
_, err := db.GetEngine(ctx).Table("comment"). | ||
Where(builder.In("issue_id", | ||
builder.Select("issue.id"). | ||
From("issue"). | ||
InnerJoin("repository", "issue.repo_id = repository.id"). | ||
Where(builder.Eq{ | ||
"repository.original_service_type": tp, | ||
}), | ||
)). | ||
And("comment.original_author_id = ?", originalAuthorID). | ||
Update(map[string]any{ | ||
"poster_id": posterID, | ||
"original_author": "", | ||
"original_author_id": 0, | ||
}) | ||
return err | ||
const batchSize = 50 | ||
for { | ||
commentIDs := make([]int64, 0, batchSize) | ||
if err := db.GetEngine(ctx). | ||
Table("comment"). | ||
Select("`comment`.id"). | ||
Join("INNER", "issue", "`comment`.issue_id = `issue`.id"). | ||
Join("INNER", "repository", "`repository`.id = `issue`.repo_id"). | ||
Where("`repository`.original_service_type = ? AND `comment`.original_author_id = ?", tp, originalAuthorID). | ||
Limit(batchSize, 0). | ||
Find(&commentIDs); err != nil { | ||
return err | ||
} | ||
|
||
for _, commentID := range commentIDs { | ||
if _, err := db.GetEngine(ctx).Table(&Comment{}).ID(commentID).Update(map[string]any{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woohoo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. per #28500 (comment), I think we can reduce the requests times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how that reduces the requests. |
||
"poster_id": posterID, | ||
"original_author": "", | ||
"original_author_id": 0, | ||
}); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if len(commentIDs) < batchSize { | ||
break | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// CreateAutoMergeComment is a internal function, only use it for CommentTypePRScheduledToAutoMerge and CommentTypePRUnScheduledToAutoMerge CommentTypes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can first interate all the special repositories since they will not be expected too much.