fix: add summary statistics switch (#21987)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2025-01-18 06:15:15 +08:00
committed by GitHub
parent 36047f2043
commit bfb7caaaf3
2 changed files with 14 additions and 6 deletions

View File

@@ -684,11 +684,19 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
var totalCnt int
var totalJson jsonutils.JSONObject
if pagingConf == nil {
// calculate total
totalQ := q.CountQuery()
totalCnt, totalJson, err = manager.CustomizedTotalCount(ctx, userCred, query, totalQ)
if err != nil {
return nil, errors.Wrap(err, "CustomizedTotalCount")
summaryStats := jsonutils.QueryBoolean(query, "summary_stats", false)
if summaryStats {
// calculate total
totalQ := q.CountQuery()
totalCnt, totalJson, err = manager.CustomizedTotalCount(ctx, userCred, query, totalQ)
if err != nil {
return nil, errors.Wrap(err, "CustomizedTotalCount")
}
} else {
totalCnt, err = q.CountWithError()
if err != nil {
return nil, errors.Wrap(err, "CountWithError")
}
}
//log.Debugf("total count %d", totalCnt)
if totalCnt == 0 {

View File

@@ -884,7 +884,7 @@ func (manager *SGuestManager) initAdminSecgroupId() error {
adminSecId := adminSec.Id
guests := make([]SGuest, 0, 10)
q := manager.Query()
q = q.In("hypervisor", []string{api.HYPERVISOR_KVM}).IsNullOrEmpty("admin_secgrp_id")
q = q.In("hypervisor", []string{api.HYPERVISOR_KVM, api.HYPERVISOR_POD}).IsNullOrEmpty("admin_secgrp_id")
err := db.FetchModelObjects(manager, q, &guests)
if err != nil {
return errors.Wrap(err, "db.FetchModelObjects")