From 8f5ab59eae41e7c210b48c2e2fbe8ec3fe5f7249 Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Wed, 25 Oct 2023 11:14:51 +0200 Subject: [PATCH 1/2] fix: count total executions for single test suite, not all --- internal/app/api/v1/testsuites.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/app/api/v1/testsuites.go b/internal/app/api/v1/testsuites.go index ee0fbfb01c1..dfbfcff879a 100644 --- a/internal/app/api/v1/testsuites.go +++ b/internal/app/api/v1/testsuites.go @@ -673,7 +673,8 @@ func (s TestkubeAPI) ListTestSuiteExecutionsHandler() fiber.Handler { if err != nil { return s.Error(c, http.StatusInternalServerError, fmt.Errorf("%s: client could not get total executions: %w", errPrefix, err)) } - allExecutionsTotals, err := s.TestExecutionResults.GetExecutionsTotals(ctx) + nameFilter := testresult.NewExecutionsFilter().WithName(c.Query("id", "")) + allExecutionsTotals, err := s.TestExecutionResults.GetExecutionsTotals(ctx, nameFilter) if err != nil { return s.Error(c, http.StatusInternalServerError, fmt.Errorf("%s: client could not get all total executions: %w", errPrefix, err)) } From 01f04c6e0053d51a7452e6f2a2358a77c3b0dc7b Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Wed, 25 Oct 2023 11:15:08 +0200 Subject: [PATCH 2/2] feat: optimize getting latest tests/test suites queries --- pkg/repository/result/mongo.go | 3 ++- pkg/repository/testresult/mongo.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/repository/result/mongo.go b/pkg/repository/result/mongo.go index b64a5c46a5c..bfffaf97f5b 100644 --- a/pkg/repository/result/mongo.go +++ b/pkg/repository/result/mongo.go @@ -160,7 +160,8 @@ func (r *MongoRepository) GetLatestByTests(ctx context.Context, testNames []stri conditions = append(conditions, bson.M{"testname": testName}) } - pipeline := []bson.D{{{Key: "$match", Value: bson.M{"$or": conditions}}}} + pipeline := []bson.D{{{Key: "$project", Value: bson.D{{Key: "_id", Value: 1}, {Key: "id", Value: 1}, {Key: "testname", Value: 1}, {Key: sortField, Value: 1}}}}} + pipeline = append(pipeline, bson.D{{Key: "$match", Value: bson.M{"$or": conditions}}}) pipeline = append(pipeline, bson.D{{Key: "$sort", Value: bson.D{{Key: sortField, Value: -1}}}}) pipeline = append(pipeline, bson.D{ {Key: "$group", Value: bson.D{{Key: "_id", Value: "$testname"}, {Key: "latest_id", Value: bson.D{{Key: "$first", Value: "$id"}}}}}}) diff --git a/pkg/repository/testresult/mongo.go b/pkg/repository/testresult/mongo.go index 712aa6fafb8..ff62f580122 100644 --- a/pkg/repository/testresult/mongo.go +++ b/pkg/repository/testresult/mongo.go @@ -76,7 +76,8 @@ func (r *MongoRepository) GetLatestByTestSuites(ctx context.Context, testSuiteNa conditions = append(conditions, bson.M{"testsuite.name": testSuiteName}) } - pipeline := []bson.D{{{Key: "$match", Value: bson.M{"$or": conditions}}}} + pipeline := []bson.D{{{Key: "$project", Value: bson.D{{Key: "_id", Value: 1}, {Key: "id", Value: 1}, {Key: "testsuite.name", Value: 1}, {Key: sortField, Value: 1}}}}} + pipeline = append(pipeline, bson.D{{Key: "$match", Value: bson.M{"$or": conditions}}}) pipeline = append(pipeline, bson.D{{Key: "$sort", Value: bson.D{{Key: sortField, Value: -1}}}}) pipeline = append(pipeline, bson.D{ {Key: "$group", Value: bson.D{{Key: "_id", Value: "$testsuite.name"}, {Key: "latest_id", Value: bson.D{{Key: "$first", Value: "$id"}}}}}})