Skip to content

Commit 83cb1c7

Browse files
Andrew Farriesroboquat
authored andcommitted
Make function output stable
Ensure that the `queriesForCustomersWithAttributionIDs` is stable by sorting the the attributionIDs before mapping them to queries. Iteration of map keys is not stable in Go.
1 parent c031a86 commit 83cb1c7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

components/usage/pkg/stripe/stripe.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"os"
12+
"sort"
1213
"strings"
1314

1415
"github.com/gitpod-io/gitpod/usage/pkg/db"
@@ -247,10 +248,11 @@ func GetAttributionID(ctx context.Context, customer *stripe.Customer) (db.Attrib
247248
// It returns multiple queries, each being a big disjunction of subclauses so that we can process multiple teamIds in one query.
248249
// `clausesPerQuery` is a limit enforced by the Stripe API.
249250
func queriesForCustomersWithAttributionIDs(creditsByAttributionID map[db.AttributionID]int64) []string {
250-
attributionIDs := make([]db.AttributionID, 0, len(creditsByAttributionID))
251+
attributionIDs := make([]string, 0, len(creditsByAttributionID))
251252
for k := range creditsByAttributionID {
252-
attributionIDs = append(attributionIDs, k)
253+
attributionIDs = append(attributionIDs, string(k))
253254
}
255+
sort.Strings(attributionIDs)
254256

255257
const clausesPerQuery = 10
256258
var queries []string

0 commit comments

Comments
 (0)