summaryrefslogtreecommitdiffstats
path: root/models/issue_comment.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-04-18 13:00:03 +0800
committertechknowlogick <matti@mdranta.net>2019-04-18 01:00:03 -0400
commitdd1acd7ce4b4afc5d1c803f85767def242a899bb (patch)
tree785f7698189353f46af91352fb71a086f2080968 /models/issue_comment.go
parent2262811e407facea09047e94aa1850c192511587 (diff)
downloadgitea-dd1acd7ce4b4afc5d1c803f85767def242a899bb.tar.gz
gitea-dd1acd7ce4b4afc5d1c803f85767def242a899bb.zip
Comments list performance optimization (#5305)
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r--models/issue_comment.go66
1 files changed, 40 insertions, 26 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go
index 360f5a6594..a1c2364b0b 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -154,6 +154,34 @@ func (c *Comment) LoadIssue() (err error) {
return
}
+func (c *Comment) loadPoster(e Engine) (err error) {
+ if c.Poster != nil {
+ return nil
+ }
+
+ c.Poster, err = getUserByID(e, c.PosterID)
+ if err != nil {
+ if IsErrUserNotExist(err) {
+ c.PosterID = -1
+ c.Poster = NewGhostUser()
+ } else {
+ log.Error("getUserByID[%d]: %v", c.ID, err)
+ }
+ }
+ return err
+}
+
+func (c *Comment) loadAttachments(e Engine) (err error) {
+ if len(c.Attachments) > 0 {
+ return
+ }
+ c.Attachments, err = getAttachmentsByCommentID(e, c.ID)
+ if err != nil {
+ log.Error("getAttachmentsByCommentID[%d]: %v", c.ID, err)
+ }
+ return err
+}
+
// AfterDelete is invoked from XORM after the object is deleted.
func (c *Comment) AfterDelete() {
if c.ID <= 0 {
@@ -997,32 +1025,6 @@ func FindComments(opts FindCommentsOptions) ([]*Comment, error) {
return findComments(x, opts)
}
-// GetCommentsByIssueID returns all comments of an issue.
-func GetCommentsByIssueID(issueID int64) ([]*Comment, error) {
- return findComments(x, FindCommentsOptions{
- IssueID: issueID,
- Type: CommentTypeUnknown,
- })
-}
-
-// GetCommentsByIssueIDSince returns a list of comments of an issue since a given time point.
-func GetCommentsByIssueIDSince(issueID, since int64) ([]*Comment, error) {
- return findComments(x, FindCommentsOptions{
- IssueID: issueID,
- Type: CommentTypeUnknown,
- Since: since,
- })
-}
-
-// GetCommentsByRepoIDSince returns a list of comments for all issues in a repo since a given time point.
-func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {
- return findComments(x, FindCommentsOptions{
- RepoID: repoID,
- Type: CommentTypeUnknown,
- Since: since,
- })
-}
-
// UpdateComment updates information of comment.
func UpdateComment(doer *User, c *Comment, oldContent string) error {
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
@@ -1039,6 +1041,9 @@ func UpdateComment(doer *User, c *Comment, oldContent string) error {
if err := c.Issue.LoadAttributes(); err != nil {
return err
}
+ if err := c.loadPoster(x); err != nil {
+ return err
+ }
mode, _ := AccessLevel(doer, c.Issue.Repo)
if err := PrepareWebhooks(c.Issue.Repo, HookEventIssueComment, &api.IssueCommentPayload{
@@ -1087,6 +1092,7 @@ func DeleteComment(doer *User, comment *Comment) error {
if err := sess.Commit(); err != nil {
return err
}
+ sess.Close()
if err := comment.LoadPoster(); err != nil {
return err
@@ -1098,6 +1104,9 @@ func DeleteComment(doer *User, comment *Comment) error {
if err := comment.Issue.LoadAttributes(); err != nil {
return err
}
+ if err := comment.loadPoster(x); err != nil {
+ return err
+ }
mode, _ := AccessLevel(doer, comment.Issue.Repo)
@@ -1154,6 +1163,11 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
if err := issue.loadRepo(e); err != nil {
return nil, err
}
+
+ if err := CommentList(comments).loadPosters(e); err != nil {
+ return nil, err
+ }
+
// Find all reviews by ReviewID
reviews := make(map[int64]*Review)
var ids = make([]int64, 0, len(comments))