Skip to content

Commit

Permalink
feat: improve performance for slowest operations / fix: loading total…
Browse files Browse the repository at this point in the history
… executions number for test suite (#4507)

* fix: count total executions for single test suite, not all
* feat: optimize getting latest tests/test suites queries
  • Loading branch information
rangoo94 authored Oct 25, 2023
1 parent 40bcd2f commit c20acea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/app/api/v1/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/repository/result/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}}}})
Expand Down
3 changes: 2 additions & 1 deletion pkg/repository/testresult/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}}}})
Expand Down

0 comments on commit c20acea

Please sign in to comment.