Skip to content

Commit a4cab2b

Browse files
authored
[BugFix] ReviewCount: GetApprovalCounts func sorted wrong (#11086)
* FIX by simplify * code reformat and optimize
1 parent 0040f8b commit a4cab2b

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

models/issue_list.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -523,29 +523,27 @@ func (issues IssueList) GetApprovalCounts() (map[int64][]*ReviewCount, error) {
523523
}
524524

525525
func (issues IssueList) getApprovalCounts(e Engine) (map[int64][]*ReviewCount, error) {
526-
rCounts := make([]*ReviewCount, 0, 6*len(issues))
526+
rCounts := make([]*ReviewCount, 0, 2*len(issues))
527527
ids := make([]int64, len(issues))
528528
for i, issue := range issues {
529529
ids[i] = issue.ID
530530
}
531531
sess := e.In("issue_id", ids)
532-
err := sess.Select("issue_id, type, count(id) as `count`").Where("official = ?", true).GroupBy("issue_id, type").OrderBy("issue_id").Table("review").Find(&rCounts)
532+
err := sess.Select("issue_id, type, count(id) as `count`").
533+
Where("official = ?", true).
534+
GroupBy("issue_id, type").
535+
OrderBy("issue_id").
536+
Table("review").
537+
Find(&rCounts)
533538
if err != nil {
534539
return nil, err
535540
}
536541

537542
approvalCountMap := make(map[int64][]*ReviewCount, len(issues))
538-
if len(rCounts) > 0 {
539-
start := 0
540-
lastID := rCounts[0].IssueID
541-
for i, current := range rCounts[1:] {
542-
if lastID != current.IssueID {
543-
approvalCountMap[lastID] = rCounts[start:i]
544-
start = i
545-
lastID = current.IssueID
546-
}
547-
}
548-
approvalCountMap[lastID] = rCounts[start:]
543+
544+
for _, c := range rCounts {
545+
approvalCountMap[c.IssueID] = append(approvalCountMap[c.IssueID], c)
549546
}
547+
550548
return approvalCountMap, nil
551549
}

0 commit comments

Comments
 (0)