From 79e348688a929419a88303003f7e91bf7b842218 Mon Sep 17 00:00:00 2001 From: ioito Date: Thu, 8 Dec 2022 15:52:57 +0800 Subject: [PATCH] fix(common): limit request --- cmd/climc/shell/misc/feature.go | 1 + pkg/cloudid/models/cloudaccount.go | 6 +++--- pkg/monitor/alerting/conditions/query.go | 2 +- pkg/monitor/models/helper.go | 2 +- pkg/monitor/models/meteralert.go | 2 +- pkg/monitor/models/monitor_resource_sync.go | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/climc/shell/misc/feature.go b/cmd/climc/shell/misc/feature.go index 0811d6d23c..0f8e09465c 100644 --- a/cmd/climc/shell/misc/feature.go +++ b/cmd/climc/shell/misc/feature.go @@ -47,6 +47,7 @@ func init() { "apsara", "cloudpods", "hcso", + "hcsop", "hcs", "nutanix", "s3", diff --git a/pkg/cloudid/models/cloudaccount.go b/pkg/cloudid/models/cloudaccount.go index 3bbfb97142..de5ceb22ae 100644 --- a/pkg/cloudid/models/cloudaccount.go +++ b/pkg/cloudid/models/cloudaccount.go @@ -94,7 +94,7 @@ func (manager *SCloudaccountManager) GetICloudaccounts() ([]SCloudaccount, error offset := int64(0) params := jsonutils.NewDict() params.Set("scope", jsonutils.NewString("system")) - params.Set("limit", jsonutils.NewInt(1024)) + params.Set("limit", jsonutils.NewInt(20)) for { params.Set("offset", jsonutils.NewInt(offset)) result, err := modules.Cloudaccounts.List(s, params) @@ -102,10 +102,10 @@ func (manager *SCloudaccountManager) GetICloudaccounts() ([]SCloudaccount, error return nil, errors.Wrap(err, "modules.Cloudaccounts.List") } data = append(data, result.Data...) - if len(data) >= result.Total { + if len(data) >= result.Total || len(result.Data) == 0 { break } - offset += 1024 + offset += 20 } accounts := []SCloudaccount{} diff --git a/pkg/monitor/alerting/conditions/query.go b/pkg/monitor/alerting/conditions/query.go index 42f035fee1..ae95d23697 100644 --- a/pkg/monitor/alerting/conditions/query.go +++ b/pkg/monitor/alerting/conditions/query.go @@ -608,7 +608,7 @@ func ListAllResources(manager modulebase.Manager, params *jsonutils.JSONDict) ([ params = jsonutils.NewDict() } params.Add(jsonutils.NewString("system"), "scope") - params.Add(jsonutils.NewInt(0), "limit") + params.Add(jsonutils.NewInt(20), "limit") params.Add(jsonutils.NewBool(true), "details") var count int session := auth.GetAdminSession(context.Background(), "") diff --git a/pkg/monitor/models/helper.go b/pkg/monitor/models/helper.go index 37fa915d65..82e09bc3b0 100644 --- a/pkg/monitor/models/helper.go +++ b/pkg/monitor/models/helper.go @@ -36,7 +36,7 @@ func FetchAllRemoteDomainProjects(ctx context.Context) ([]*db.STenant, []*db.STe for { listParam := jsonutils.NewDict() listParam.Add(jsonutils.NewString("system"), "scope") - listParam.Add(jsonutils.NewInt(0), "limit") + listParam.Add(jsonutils.NewInt(20), "limit") listParam.Add(jsonutils.NewInt(int64(count)), "offset") listParam.Add(jsonutils.JSONTrue, "details") result, err := identity.Projects.List(s, listParam) diff --git a/pkg/monitor/models/meteralert.go b/pkg/monitor/models/meteralert.go index 7514a8c8d4..d65e270fbe 100644 --- a/pkg/monitor/models/meteralert.go +++ b/pkg/monitor/models/meteralert.go @@ -106,7 +106,7 @@ func (man *SMeterAlertManager) getAllBillAccounts(ctx context.Context) ([]jsonut q := jsonutils.NewDict() q.Add(jsonutils.NewString("system"), "scope") q.Add(jsonutils.NewInt(int64(len(results))), "offset") - q.Add(jsonutils.NewInt(2048), "limit") + q.Add(jsonutils.NewInt(20), "limit") ret, err := compute.Cloudaccounts.List(s, q) if err != nil { return nil, err diff --git a/pkg/monitor/models/monitor_resource_sync.go b/pkg/monitor/models/monitor_resource_sync.go index cfc6ab1e00..954243518c 100644 --- a/pkg/monitor/models/monitor_resource_sync.go +++ b/pkg/monitor/models/monitor_resource_sync.go @@ -337,7 +337,7 @@ func ListAllResources(manager modulebase.Manager, params *jsonutils.JSONDict) ([ params = jsonutils.NewDict() } params.Add(jsonutils.NewString("system"), "scope") - params.Add(jsonutils.NewInt(0), "limit") + params.Add(jsonutils.NewInt(20), "limit") params.Add(jsonutils.NewBool(true), "details") var count int session := auth.GetAdminSession(context.Background(), "")