Skip to content

Commit

Permalink
fix: add summary statistics switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiu Jian committed Jan 16, 2025
1 parent 324cfe0 commit fd0e5c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions pkg/cloudcommon/db/db_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/models/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit fd0e5c0

Please sign in to comment.