diff options
author | 6543 <6543@obermui.de> | 2020-04-16 12:44:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 13:44:34 +0300 |
commit | a4cab2bbfa0f91af8c14b0c25f012ed0b7271280 (patch) | |
tree | fdf0e700e68c000c9e73eb03c096ea1261b7e308 /models/issue_list.go | |
parent | 0040f8bf67f29e9666c7562172bb38207296e8cd (diff) | |
download | gitea-a4cab2bbfa0f91af8c14b0c25f012ed0b7271280.tar.gz gitea-a4cab2bbfa0f91af8c14b0c25f012ed0b7271280.zip |
[BugFix] ReviewCount: GetApprovalCounts func sorted wrong (#11086)
* FIX by simplify
* code reformat and optimize
Diffstat (limited to 'models/issue_list.go')
-rw-r--r-- | models/issue_list.go | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/models/issue_list.go b/models/issue_list.go index e6ca3fc890..628058eb35 100644 --- a/models/issue_list.go +++ b/models/issue_list.go @@ -523,29 +523,27 @@ func (issues IssueList) GetApprovalCounts() (map[int64][]*ReviewCount, error) { } func (issues IssueList) getApprovalCounts(e Engine) (map[int64][]*ReviewCount, error) { - rCounts := make([]*ReviewCount, 0, 6*len(issues)) + rCounts := make([]*ReviewCount, 0, 2*len(issues)) ids := make([]int64, len(issues)) for i, issue := range issues { ids[i] = issue.ID } sess := e.In("issue_id", ids) - err := sess.Select("issue_id, type, count(id) as `count`").Where("official = ?", true).GroupBy("issue_id, type").OrderBy("issue_id").Table("review").Find(&rCounts) + err := sess.Select("issue_id, type, count(id) as `count`"). + Where("official = ?", true). + GroupBy("issue_id, type"). + OrderBy("issue_id"). + Table("review"). + Find(&rCounts) if err != nil { return nil, err } approvalCountMap := make(map[int64][]*ReviewCount, len(issues)) - if len(rCounts) > 0 { - start := 0 - lastID := rCounts[0].IssueID - for i, current := range rCounts[1:] { - if lastID != current.IssueID { - approvalCountMap[lastID] = rCounts[start:i] - start = i - lastID = current.IssueID - } - } - approvalCountMap[lastID] = rCounts[start:] + + for _, c := range rCounts { + approvalCountMap[c.IssueID] = append(approvalCountMap[c.IssueID], c) } + return approvalCountMap, nil } |