Skip to content

Commit aeafe3d

Browse files
committed
Optimize FindCommitLineComments to filter in memory
Filter by tree path in memory instead of in database query to avoid requiring a new database index. This improves performance by using existing indexes on commit_sha and type.
1 parent 7ae6e20 commit aeafe3d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

models/issues/comment.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,14 +1101,27 @@ func FindCommitComments(ctx context.Context, repoID int64, commitSHA string) (Co
11011101

11021102
// FindCommitLineComments finds code comments for a specific file and line in a commit
11031103
func FindCommitLineComments(ctx context.Context, commitSHA, treePath string) (CommentList, error) {
1104-
comments := make([]*Comment, 0, 10)
1105-
return comments, db.GetEngine(ctx).
1104+
// Fetch all commit code comments for this commit (filter by tree path in memory to avoid needing a new index)
1105+
allComments := make([]*Comment, 0, 10)
1106+
err := db.GetEngine(ctx).
11061107
Where("commit_sha = ?", commitSHA).
1107-
And("tree_path = ?", treePath).
11081108
And("type = ?", CommentTypeCommitCode).
11091109
Asc("created_unix").
11101110
Asc("id").
1111-
Find(&comments)
1111+
Find(&allComments)
1112+
if err != nil {
1113+
return nil, err
1114+
}
1115+
1116+
// Filter in memory by tree path
1117+
comments := make(CommentList, 0, len(allComments))
1118+
for _, comment := range allComments {
1119+
if comment.TreePath == treePath {
1120+
comments = append(comments, comment)
1121+
}
1122+
}
1123+
1124+
return comments, nil
11121125
}
11131126

11141127
// UpdateCommentInvalidate updates comment invalidated column

0 commit comments

Comments
 (0)