diff --git a/graphql/query_resolver.go b/graphql/query_resolver.go index 8c008cc956..4091c117a5 100644 --- a/graphql/query_resolver.go +++ b/graphql/query_resolver.go @@ -1000,15 +1000,23 @@ func (r *queryResolver) Waterfall(ctx context.Context, options WaterfallOptions) // Since GetAllWaterfallVersions uses an inclusive order range ($gte instead of $gt), add 1 to our minimum range minVersionOrder := minOrderOpt + 1 - if minOrderOpt == 0 { + if minOrderOpt == 0 && len(activeVersions) != 0 { // Only use the last active version order number if no minOrder was provided. Using the activeVersions bounds may omit inactive versions between the min and the last active version found. minVersionOrder = activeVersions[len(activeVersions)-1].RevisionOrderNumber + } else if len(activeVersions) == 0 { + // If there are no active versions, use 0 to fetch all inactive versions + minVersionOrder = 0 } // Same as above, but subtract for max order maxVersionOrder := maxOrderOpt - 1 - if maxOrderOpt == 0 { - // Same as above: only use the first active version if no maxOrder was specified to avoid omitting inactive versions. + if len(activeVersions) == 0 { + maxVersionOrder = 0 + } else if maxOrderOpt == 0 && minOrderOpt == 0 { + // If no order options were specified, we're on the first page and should not put a limit on the first version returned so that we don't omit inactive versions + maxVersionOrder = 0 + } else if maxOrderOpt == 0 { + // If we're paginating backwards, use the newest active version as the upper bound maxVersionOrder = activeVersions[0].RevisionOrderNumber } @@ -1027,16 +1035,18 @@ func (r *queryResolver) Waterfall(ctx context.Context, options WaterfallOptions) } waterfallVersions := groupInactiveVersions(activeVersionIds, allVersions) + bv := []*model.WaterfallBuildVariant{} - buildVariants, err := model.GetWaterfallBuildVariants(ctx, activeVersionIds) - if err != nil { - return nil, InternalServerError.Send(ctx, fmt.Sprintf("getting waterfall build variants: %s", err.Error())) - } + if len(activeVersionIds) > 0 { + buildVariants, err := model.GetWaterfallBuildVariants(ctx, activeVersionIds) + if err != nil { + return nil, InternalServerError.Send(ctx, fmt.Sprintf("getting waterfall build variants: %s", err.Error())) + } - bv := []*model.WaterfallBuildVariant{} - for _, b := range buildVariants { - bCopy := b - bv = append(bv, &bCopy) + for _, b := range buildVariants { + bCopy := b + bv = append(bv, &bCopy) + } } // Return the min and max orders returned to be used as parameters for navigating to the next page diff --git a/graphql/tests/query/waterfall/data.json b/graphql/tests/query/waterfall/data.json index 0d53b85f6e..91c0e09f6b 100644 --- a/graphql/tests/query/waterfall/data.json +++ b/graphql/tests/query/waterfall/data.json @@ -89,6 +89,36 @@ "author": "mohamed.khelif", "status": "created", "order": 45 + }, + { + "_id": "inactive1", + "gitspec": "abc", + "identifier": "mci", + "r": "gitter_request", + "activated": false, + "author": "sophie.stadler", + "status": "inactive", + "order": 1 + }, + { + "_id": "inactive2", + "gitspec": "abc", + "identifier": "mci", + "r": "gitter_request", + "activated": false, + "author": "sophie.stadler", + "status": "inactive", + "order": 2 + }, + { + "_id": "inactive3", + "gitspec": "abc", + "identifier": "mci", + "r": "gitter_request", + "activated": false, + "author": "sophie.stadler", + "status": "inactive", + "order": 3 } ], "tasks": [ @@ -169,8 +199,8 @@ "identifier": "spruce-identifier" }, { - "_id": "evergreen", - "identifier": "evergreen" + "_id": "mci", + "identifier": "mci" } ], "builds": [ diff --git a/graphql/tests/query/waterfall/queries/all_inactive_versions.graphql b/graphql/tests/query/waterfall/queries/all_inactive_versions.graphql new file mode 100644 index 0000000000..4fadc6427c --- /dev/null +++ b/graphql/tests/query/waterfall/queries/all_inactive_versions.graphql @@ -0,0 +1,20 @@ +{ + waterfall(options: { projectIdentifier: "mci" }) { + nextPageOrder + prevPageOrder + versions { + version { + activated + author + id + order + } + inactiveVersions { + activated + author + id + order + } + } + } +} diff --git a/graphql/tests/query/waterfall/results.json b/graphql/tests/query/waterfall/results.json index 40f592a9d6..6bfd501be8 100644 --- a/graphql/tests/query/waterfall/results.json +++ b/graphql/tests/query/waterfall/results.json @@ -252,6 +252,42 @@ } } } + }, + { + "query_file": "all_inactive_versions.graphql", + "result": { + "data": { + "waterfall": { + "nextPageOrder": 1, + "prevPageOrder": 0, + "versions": [ + { + "version": null, + "inactiveVersions": [ + { + "activated": false, + "author": "sophie.stadler", + "id": "inactive3", + "order": 3 + }, + { + "activated": false, + "author": "sophie.stadler", + "id": "inactive2", + "order": 2 + }, + { + "activated": false, + "author": "sophie.stadler", + "id": "inactive1", + "order": 1 + } + ] + } + ] + } + } + } } ] } diff --git a/model/waterfall.go b/model/waterfall.go index 106a6ce7a7..ac0900c0ff 100644 --- a/model/waterfall.go +++ b/model/waterfall.go @@ -103,7 +103,8 @@ func GetActiveWaterfallVersions(ctx context.Context, projectId string, opts Wate // GetAllWaterfallVersions returns all of a project's versions within an inclusive range of orders. func GetAllWaterfallVersions(ctx context.Context, projectId string, minOrder int, maxOrder int) ([]Version, error) { - if minOrder >= maxOrder { + hasOrderFilters := maxOrder != 0 && minOrder != 0 + if hasOrderFilters && minOrder >= maxOrder { return nil, errors.New("minOrder must be less than maxOrder") } @@ -112,10 +113,17 @@ func GetAllWaterfallVersions(ctx context.Context, projectId string, minOrder int VersionRequesterKey: bson.M{ "$in": evergreen.SystemVersionRequesterTypes, }, - VersionRevisionOrderNumberKey: bson.M{ - "$gte": minOrder, - "$lte": maxOrder, - }, + } + + if hasOrderFilters { + revisionFilter := bson.M{} + if minOrder != 0 { + revisionFilter["$gte"] = minOrder + } + if maxOrder != 0 { + revisionFilter["$lte"] = maxOrder + } + match[VersionRevisionOrderNumberKey] = revisionFilter } pipeline := []bson.M{{"$match": match}} diff --git a/model/waterfall_test.go b/model/waterfall_test.go index e323df3506..21eb94c2d0 100644 --- a/model/waterfall_test.go +++ b/model/waterfall_test.go @@ -191,6 +191,10 @@ func TestGetAllWaterfallVersions(t *testing.T) { assert.NoError(t, err) require.Len(t, versions, 1) assert.EqualValues(t, "v_1", versions[0].Id) + + versions, err = GetAllWaterfallVersions(ctx, p.Id, 0, 0) + assert.NoError(t, err) + require.Len(t, versions, 5) } func TestGetWaterfallBuildVariants(t *testing.T) {