fix
This commit is contained in:
@@ -93,6 +93,34 @@ func (s *SummaryService) Summary(c *gin.Context) (*HomepageSummary, error) {
|
|||||||
SiteURls: lo.Map(dep.SettingProvider().AllSiteURLs(c), func(item *url.URL, index int) string {
|
SiteURls: lo.Map(dep.SettingProvider().AllSiteURLs(c), func(item *url.URL, index int) string {
|
||||||
return item.String()
|
return item.String()
|
||||||
}),
|
}),
|
||||||
|
StoragePolicies: make([]*StoragePolicySpace, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
// 无论是否从缓存加载或生成新统计,都需要获取存储策略空间使用情况
|
||||||
|
policyClient := dep.StoragePolicyClient()
|
||||||
|
policyResult, policyErr := policyClient.ListPolicies(c, &inventory.ListPolicyParameters{
|
||||||
|
PaginationArgs: &inventory.PaginationArgs{PageSize: 1000, Page: 0}, // 获取所有策略
|
||||||
|
})
|
||||||
|
if policyErr == nil {
|
||||||
|
// 收集存储策略空间使用情况
|
||||||
|
res.StoragePolicies = make([]*StoragePolicySpace, 0, len(policyResult.Policies))
|
||||||
|
entityClient := dep.FileClient()
|
||||||
|
|
||||||
|
for _, policy := range policyResult.Policies {
|
||||||
|
// 获取该存储策略的已使用空间
|
||||||
|
_, usedSpace, err := entityClient.CountEntityByStoragePolicyID(c, policy.ID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
res.StoragePolicies = append(res.StoragePolicies, &StoragePolicySpace{
|
||||||
|
ID: int64(policy.ID),
|
||||||
|
Name: policy.Name,
|
||||||
|
Type: policy.Type,
|
||||||
|
Used: int64(usedSpace),
|
||||||
|
Total: int64(policy.MaxSize), // 确保类型一致
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if summary, ok := kv.Get(MetricCacheKey); ok {
|
if summary, ok := kv.Get(MetricCacheKey); ok {
|
||||||
@@ -161,33 +189,6 @@ func (s *SummaryService) Summary(c *gin.Context) (*HomepageSummary, error) {
|
|||||||
_ = kv.Set(MetricCacheKey, *summary, 86400)
|
_ = kv.Set(MetricCacheKey, *summary, 86400)
|
||||||
res.MetricsSummary = summary
|
res.MetricsSummary = summary
|
||||||
|
|
||||||
// 获取存储策略空间使用数据
|
|
||||||
policyClient := dep.StoragePolicyClient()
|
|
||||||
policyResult, err := policyClient.ListPolicies(c, &inventory.ListPolicyParameters{
|
|
||||||
PaginationArgs: &inventory.PaginationArgs{PageSize: 1000, Page: 0}, // 获取所有策略
|
|
||||||
})
|
|
||||||
if err == nil {
|
|
||||||
// 收集存储策略空间使用情况
|
|
||||||
res.StoragePolicies = make([]*StoragePolicySpace, 0, len(policyResult.Policies))
|
|
||||||
entityClient := dep.FileClient()
|
|
||||||
|
|
||||||
for _, policy := range policyResult.Policies {
|
|
||||||
// 获取该存储策略的已使用空间
|
|
||||||
_, usedSpace, err := entityClient.CountEntityByStoragePolicyID(c, policy.ID)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
res.StoragePolicies = append(res.StoragePolicies, &StoragePolicySpace{
|
|
||||||
ID: int64(policy.ID),
|
|
||||||
Name: policy.Name,
|
|
||||||
Type: policy.Type,
|
|
||||||
Used: int64(usedSpace),
|
|
||||||
Total: int64(policy.MaxSize), // 确保类型一致
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user