From 6d0c41ca94043c415315a55ec4a947350f1e9901 Mon Sep 17 00:00:00 2001 From: yuvrajangadsingh Date: Mon, 9 Mar 2026 02:16:57 +0530 Subject: [PATCH] fix: address lunny's review comments - use single query with Cols("comment_id").Table("commit_comment") instead of loading full CommitComment structs - remove models/repo/commit_comment.go entirely --- models/issues/commit_comment.go | 13 ++++--------- models/repo/commit_comment.go | 8 -------- 2 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 models/repo/commit_comment.go diff --git a/models/issues/commit_comment.go b/models/issues/commit_comment.go index 2b4e38a43f..297b97ce6c 100644 --- a/models/issues/commit_comment.go +++ b/models/issues/commit_comment.go @@ -35,22 +35,17 @@ type CommitCommentsForDiff map[string]*FileCommitComments // FindCommitCommentsByCommitSHA returns all comments for a given commit in a repo. func FindCommitCommentsByCommitSHA(ctx context.Context, repoID int64, commitSHA string) ([]*Comment, error) { - var refs []CommitComment - if err := db.GetEngine(ctx). + var commentIDs []int64 + if err := db.GetEngine(ctx).Cols("comment_id").Table("commit_comment"). Where("repo_id = ? AND commit_sha = ?", repoID, commitSHA). - Find(&refs); err != nil { + Find(&commentIDs); err != nil { return nil, err } - if len(refs) == 0 { + if len(commentIDs) == 0 { return nil, nil } - commentIDs := make([]int64, 0, len(refs)) - for _, ref := range refs { - commentIDs = append(commentIDs, ref.CommentID) - } - comments := make([]*Comment, 0, len(commentIDs)) if err := db.GetEngine(ctx). In("id", commentIDs). diff --git a/models/repo/commit_comment.go b/models/repo/commit_comment.go deleted file mode 100644 index 74657a72a0..0000000000 --- a/models/repo/commit_comment.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2026 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -// This file intentionally left minimal. The CommitComment junction table -// and all query methods now live in models/issues/commit_comment.go -// alongside the Comment model they reference. - -package repo