Skip to content

Commit 5813f01

Browse files
committed
Some small refactors
1 parent e7ef708 commit 5813f01

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

models/issues/comment_list.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (comments CommentList) LoadPosters(ctx context.Context) error {
4141

4242
func (comments CommentList) getLabelIDs() []int64 {
4343
return container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
44-
return comment.LabelID, comment.LabelID > 0
44+
return comment.LabelID, comment.LabelID > 0 && comment.Label == nil
4545
})
4646
}
4747

@@ -51,6 +51,9 @@ func (comments CommentList) loadLabels(ctx context.Context) error {
5151
}
5252

5353
labelIDs := comments.getLabelIDs()
54+
if len(labelIDs) == 0 {
55+
return nil
56+
}
5457
commentLabels := make(map[int64]*Label, len(labelIDs))
5558
left := len(labelIDs)
5659
for left > 0 {
@@ -118,8 +121,8 @@ func (comments CommentList) loadMilestones(ctx context.Context) error {
118121
milestoneIDs = milestoneIDs[limit:]
119122
}
120123

121-
for _, issue := range comments {
122-
issue.Milestone = milestoneMaps[issue.MilestoneID]
124+
for _, comment := range comments {
125+
comment.Milestone = milestoneMaps[comment.MilestoneID]
123126
}
124127
return nil
125128
}
@@ -165,7 +168,7 @@ func (comments CommentList) loadOldMilestones(ctx context.Context) error {
165168

166169
func (comments CommentList) getAssigneeIDs() []int64 {
167170
return container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
168-
return comment.AssigneeID, comment.AssigneeID > 0
171+
return comment.AssigneeID, comment.AssigneeID > 0 && comment.Assignee == nil
169172
})
170173
}
171174

@@ -175,6 +178,9 @@ func (comments CommentList) loadAssignees(ctx context.Context) error {
175178
}
176179

177180
assigneeIDs := comments.getAssigneeIDs()
181+
if len(assigneeIDs) == 0 {
182+
return nil
183+
}
178184
assignees := make(map[int64]*user_model.User, len(assigneeIDs))
179185
left := len(assigneeIDs)
180186
for left > 0 {
@@ -301,6 +307,9 @@ func (comments CommentList) loadDependentIssues(ctx context.Context) error {
301307

302308
e := db.GetEngine(ctx)
303309
issueIDs := comments.getDependentIssueIDs()
310+
if len(issueIDs) == 0 {
311+
return nil
312+
}
304313
issues := make(map[int64]*Issue, len(issueIDs))
305314
left := len(issueIDs)
306315
for left > 0 {
@@ -417,7 +426,7 @@ func (comments CommentList) LoadAttachments(ctx context.Context) (err error) {
417426

418427
func (comments CommentList) getReviewIDs() []int64 {
419428
return container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
420-
return comment.ReviewID, comment.ReviewID > 0
429+
return comment.ReviewID, comment.ReviewID > 0 && comment.Review == nil
421430
})
422431
}
423432

@@ -427,6 +436,9 @@ func (comments CommentList) loadReviews(ctx context.Context) error {
427436
}
428437

429438
reviewIDs := comments.getReviewIDs()
439+
if len(reviewIDs) == 0 {
440+
return nil
441+
}
430442
reviews := make(map[int64]*Review, len(reviewIDs))
431443
if err := db.GetEngine(ctx).In("id", reviewIDs).Find(&reviews); err != nil {
432444
return err

0 commit comments

Comments
 (0)