From 74ca4a4f015cb6845a3c3d893a9ee27e8183e321 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 20 Dec 2023 13:17:51 +0800 Subject: [PATCH 1/2] improve possible performance bottleneck --- models/issues/comment.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index ba5aed9c652e9..8676867894368 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -1160,22 +1160,20 @@ 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 + return db.Iterate[repo_model.Repository](ctx, builder.Eq{ + "repository.original_service_type": tp, + }, func(ctx context.Context, repo *repo_model.Repository) error { + _, err := db.GetEngine(ctx).Table("comment"). + Join("INNER", "issue", "issue.id = comment.issue_id"). + Where("issue.repo_id=?", repo.ID). + And("comment.original_author_id = ?", originalAuthorID). + Update(map[string]any{ + "poster_id": posterID, + "original_author": "", + "original_author_id": 0, + }) + return err + }) } // CreateAutoMergeComment is a internal function, only use it for CommentTypePRScheduledToAutoMerge and CommentTypePRUnScheduledToAutoMerge CommentTypes From 47746adb918cac4fbd0aa62b25f96ea172908c14 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 21 Dec 2023 21:37:38 +0800 Subject: [PATCH 2/2] don't interate repository --- models/issues/comment.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index 8676867894368..ce5cf5902d776 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -1160,20 +1160,17 @@ 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 { - return db.Iterate[repo_model.Repository](ctx, builder.Eq{ - "repository.original_service_type": tp, - }, func(ctx context.Context, repo *repo_model.Repository) error { - _, err := db.GetEngine(ctx).Table("comment"). - Join("INNER", "issue", "issue.id = comment.issue_id"). - Where("issue.repo_id=?", repo.ID). - And("comment.original_author_id = ?", originalAuthorID). - Update(map[string]any{ - "poster_id": posterID, - "original_author": "", - "original_author_id": 0, - }) - return err - }) + _, err := db.GetEngine(ctx).Table("comment"). + Join("INNER", "issue", "issue.id = comment.issue_id"). + Join("INNER", "repository", "issue.repo_id = repository.id"). + Where("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 } // CreateAutoMergeComment is a internal function, only use it for CommentTypePRScheduledToAutoMerge and CommentTypePRUnScheduledToAutoMerge CommentTypes