mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-03 22:52:28 +01:00
[BugFix] ReviewCount: GetApprovalCounts func sorted wrong (#11086)
* FIX by simplify * code reformat and optimize
This commit is contained in:
parent
0040f8bf67
commit
a4cab2bbfa
1 changed files with 11 additions and 13 deletions
|
@ -523,29 +523,27 @@ func (issues IssueList) GetApprovalCounts() (map[int64][]*ReviewCount, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (issues IssueList) getApprovalCounts(e Engine) (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))
|
ids := make([]int64, len(issues))
|
||||||
for i, issue := range issues {
|
for i, issue := range issues {
|
||||||
ids[i] = issue.ID
|
ids[i] = issue.ID
|
||||||
}
|
}
|
||||||
sess := e.In("issue_id", ids)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
approvalCountMap := make(map[int64][]*ReviewCount, len(issues))
|
approvalCountMap := make(map[int64][]*ReviewCount, len(issues))
|
||||||
if len(rCounts) > 0 {
|
|
||||||
start := 0
|
for _, c := range rCounts {
|
||||||
lastID := rCounts[0].IssueID
|
approvalCountMap[c.IssueID] = append(approvalCountMap[c.IssueID], c)
|
||||||
for i, current := range rCounts[1:] {
|
|
||||||
if lastID != current.IssueID {
|
|
||||||
approvalCountMap[lastID] = rCounts[start:i]
|
|
||||||
start = i
|
|
||||||
lastID = current.IssueID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
approvalCountMap[lastID] = rCounts[start:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return approvalCountMap, nil
|
return approvalCountMap, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue