From 1d8975164445d510d453524bceca72d22fc24e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Mon, 12 Aug 2024 15:47:53 +0800 Subject: [PATCH] fix(region): custom total count (#20998) --- pkg/cloudcommon/db/virtualresource.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/cloudcommon/db/virtualresource.go b/pkg/cloudcommon/db/virtualresource.go index 94178ad82ea..46646ff9218 100644 --- a/pkg/cloudcommon/db/virtualresource.go +++ b/pkg/cloudcommon/db/virtualresource.go @@ -16,6 +16,7 @@ package db import ( "context" + "database/sql" "yunion.io/x/jsonutils" "yunion.io/x/log" @@ -118,10 +119,9 @@ func (manager *SVirtualResourceBaseManager) CustomizedTotalCount(ctx context.Con StatusInfo []apis.StatusStatisticStatusInfo }{} - var err error - results.Count, err = totalQ.CountWithError() - if err != nil { - return -1, nil, errors.Wrapf(err, "CountWithError") + err := totalQ.First(&results.TotalCountBase) + if err != nil && errors.Cause(err) != sql.ErrNoRows { + return -1, nil, errors.Wrapf(err, "First") } totalSQ := totalQ.ResetFields().SubQuery()