Enhance(dashboard): optimize get policies request (#1539)
This commit is contained in:
parent
2bb28a9845
commit
fd59d1b5ca
1 changed files with 12 additions and 4 deletions
|
@ -318,12 +318,20 @@ func (service *AdminListService) Policies() serializer.Response {
|
||||||
|
|
||||||
// 统计每个策略的文件使用
|
// 统计每个策略的文件使用
|
||||||
statics := make(map[uint][2]int, len(res))
|
statics := make(map[uint][2]int, len(res))
|
||||||
|
policyIds := make([]uint, 0, len(res))
|
||||||
for i := 0; i < len(res); i++ {
|
for i := 0; i < len(res); i++ {
|
||||||
|
policyIds = append(policyIds, res[i].ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, _ := model.DB.Model(&model.File{}).Where("policy_id in (?)", policyIds).
|
||||||
|
Select("policy_id,count(id),sum(size)").Group("policy_id").Rows()
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
policyId := uint(0)
|
||||||
total := [2]int{}
|
total := [2]int{}
|
||||||
row := model.DB.Model(&model.File{}).Where("policy_id = ?", res[i].ID).
|
rows.Scan(&policyId, &total[0], &total[1])
|
||||||
Select("count(id),sum(size)").Row()
|
|
||||||
row.Scan(&total[0], &total[1])
|
statics[policyId] = total
|
||||||
statics[res[i].ID] = total
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return serializer.Response{Data: map[string]interface{}{
|
return serializer.Response{Data: map[string]interface{}{
|
||||||
|
|
Loading…
Add table
Reference in a new issue