From 8c29db0ce503a668a6cfca31c3bd34aba9aefe36 Mon Sep 17 00:00:00 2001 From: liu deyi Date: Thu, 27 Jan 2022 13:51:13 +0800 Subject: [PATCH] cherry pick to 1.9.0 Signed-off-by: liu deyi --- .../common/repository/mongodb/delivery_artifact.go | 12 ------------ .../aslan/core/stat/service/deploy_stat.go | 4 ++-- pkg/microservice/aslan/core/stat/service/overview.go | 4 ++-- pkg/microservice/aslan/core/stat/service/test.go | 2 +- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/pkg/microservice/aslan/core/common/repository/mongodb/delivery_artifact.go b/pkg/microservice/aslan/core/common/repository/mongodb/delivery_artifact.go index 2677db1757..a7fb5ebc58 100644 --- a/pkg/microservice/aslan/core/common/repository/mongodb/delivery_artifact.go +++ b/pkg/microservice/aslan/core/common/repository/mongodb/delivery_artifact.go @@ -81,18 +81,6 @@ func (c *DeliveryArtifactColl) EnsureIndex(ctx context.Context) error { return err } -func (c *DeliveryArtifactColl) Count() (int64, error) { - query := bson.M{} - - ctx := context.Background() - count, err := c.Collection.CountDocuments(ctx, query) - if err != nil { - return 0, err - } - - return count, nil -} - func (c *DeliveryArtifactColl) List(args *DeliveryArtifactArgs) ([]*models.DeliveryArtifact, int, error) { if args == nil { return nil, 0, errors.New("nil delivery_artifact args") diff --git a/pkg/microservice/aslan/core/stat/service/deploy_stat.go b/pkg/microservice/aslan/core/stat/service/deploy_stat.go index 0e0153f80a..2343047dd5 100644 --- a/pkg/microservice/aslan/core/stat/service/deploy_stat.go +++ b/pkg/microservice/aslan/core/stat/service/deploy_stat.go @@ -337,7 +337,7 @@ type deployHigherStat struct { } func GetDeployTopFiveHigherMeasure(startDate, endDate int64, productNames []string, log *zap.SugaredLogger) ([]*deployHigherStat, error) { - deployStats, err := mongodb.NewDeployStatColl().ListDeployStat(&models.DeployStatOption{StartDate: startDate, EndDate: endDate, IsAsc: true, ProductNames: productNames}) + deployStats, err := mongodb.NewDeployStatColl().ListDeployStat(&models.DeployStatOption{StartDate: startDate, EndDate: endDate, IsAsc: true, ProductNames: productNames, Limit: 5, IsMaxDeploy: true}) if err != nil { log.Errorf("ListDeployStat err:%v", err) return nil, fmt.Errorf("ListDeployStat err:%v", err) @@ -372,7 +372,7 @@ type deployFailureHigherStat struct { } func GetDeployTopFiveFailureMeasure(startDate, endDate int64, productNames []string, log *zap.SugaredLogger) ([]*deployFailureHigherStat, error) { - deployStats, err := mongodb.NewDeployStatColl().ListDeployStat(&models.DeployStatOption{StartDate: startDate, EndDate: endDate, IsAsc: true, ProductNames: productNames}) + deployStats, err := mongodb.NewDeployStatColl().ListDeployStat(&models.DeployStatOption{StartDate: startDate, EndDate: endDate, IsAsc: true, ProductNames: productNames, Limit: 5}) if err != nil { log.Errorf("ListDeployStat err:%v", err) return nil, fmt.Errorf("ListDeployStat err:%v", err) diff --git a/pkg/microservice/aslan/core/stat/service/overview.go b/pkg/microservice/aslan/core/stat/service/overview.go index 42fe239da7..1d08e0fd7f 100644 --- a/pkg/microservice/aslan/core/stat/service/overview.go +++ b/pkg/microservice/aslan/core/stat/service/overview.go @@ -62,12 +62,12 @@ func GetOverviewStat(log *zap.SugaredLogger) (*Overview, error) { } overview.EnvCount = int(envCount) - artifactCount, err := commonrepo.NewDeliveryArtifactColl().Count() + _, artifactCount, err := commonrepo.NewDeliveryArtifactColl().List(&commonrepo.DeliveryArtifactArgs{}) if err != nil { log.Errorf("Failed to get artifact count err:%s", err) return nil, err } - overview.ArtifactCount = int(artifactCount) + overview.ArtifactCount = artifactCount serviceCount, err := commonrepo.NewServiceColl().Count("") if err != nil { diff --git a/pkg/microservice/aslan/core/stat/service/test.go b/pkg/microservice/aslan/core/stat/service/test.go index 04ff69e506..e759fd8516 100644 --- a/pkg/microservice/aslan/core/stat/service/test.go +++ b/pkg/microservice/aslan/core/stat/service/test.go @@ -28,7 +28,7 @@ type testDashboard struct { TotalCaseCount int `json:"total_case_count"` TotalExecCount int `json:"total_exec_count"` Success int `json:"success"` - AverageDuration int64 `json:"average_curation"` + AverageDuration int64 `json:"average_duration"` } func GetTestDashboard(log *zap.SugaredLogger) (*testDashboard, error) {