Skip to content

Commit

Permalink
Improve handling for inactive versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Oct 2, 2024
1 parent 5b6eb17 commit f297ac8
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 18 deletions.
32 changes: 21 additions & 11 deletions graphql/query_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
34 changes: 32 additions & 2 deletions graphql/tests/query/waterfall/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -169,8 +199,8 @@
"identifier": "spruce-identifier"
},
{
"_id": "evergreen",
"identifier": "evergreen"
"_id": "mci",
"identifier": "mci"
}
],
"builds": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
waterfall(options: { projectIdentifier: "mci" }) {
nextPageOrder
prevPageOrder
versions {
version {
activated
author
id
order
}
inactiveVersions {
activated
author
id
order
}
}
}
}
36 changes: 36 additions & 0 deletions graphql/tests/query/waterfall/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
}
}
}
}
]
}
18 changes: 13 additions & 5 deletions model/waterfall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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}}
Expand Down
4 changes: 4 additions & 0 deletions model/waterfall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f297ac8

Please sign in to comment.