Skip to content

Commit 8caaff8

Browse files
authored
Check for chunk size before api call[v8] (#3574)
Co-authored-by: [email protected]
1 parent 06fc204 commit 8caaff8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

actor/v7action/resource_match.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ func (actor Actor) ResourceMatch(resources []sharedaction.V3Resource) ([]shareda
2121
)
2222

2323
for _, chunk := range resourceChunks {
24-
newMatchedAPIResources, warnings, err := actor.CloudControllerClient.ResourceMatch(chunk)
25-
allWarnings = append(allWarnings, warnings...)
26-
if err != nil {
27-
return nil, allWarnings, err
24+
if len(chunk) > 0 {
25+
newMatchedAPIResources, warnings, err := actor.CloudControllerClient.ResourceMatch(chunk)
26+
allWarnings = append(allWarnings, warnings...)
27+
if err != nil {
28+
return nil, allWarnings, err
29+
}
30+
matchedAPIResources = append(matchedAPIResources, newMatchedAPIResources...)
2831
}
29-
matchedAPIResources = append(matchedAPIResources, newMatchedAPIResources...)
3032
}
3133

3234
var matchedResources []sharedaction.V3Resource
@@ -51,8 +53,10 @@ func (Actor) chunkResources(resources []sharedaction.V3Resource) [][]ccv3.Resour
5153
}
5254

5355
if len(currentSet) == constant.MaxNumberOfResourcesForMatching || index+1 == len(resources) {
54-
chunkedResources = append(chunkedResources, currentSet)
55-
currentSet = []ccv3.Resource{}
56+
if len(currentSet) > 0 {
57+
chunkedResources = append(chunkedResources, currentSet)
58+
currentSet = []ccv3.Resource{}
59+
}
5660
}
5761
}
5862
return chunkedResources

0 commit comments

Comments
 (0)