Skip to content

Commit

Permalink
Splits large fact lists into smaller writes (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: Blaize Kaye <[email protected]>
  • Loading branch information
bomoko and Blaize Kaye authored Dec 5, 2024
1 parent 4295e89 commit 30a47d2
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions gatherers/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ func Writefacts(projectName string, environmentName string, facts []GatheredFact
}
}

// let's split the array into multidimensional arrays in case we have huge fact payloads
var factMD [][]GatheredFact

const maxFactWrite = 100
for i := 0; i < len(facts); i += maxFactWrite {
end := i + maxFactWrite
if end > len(facts) {
end = len(facts)
}
factMD = append(factMD, facts[i:end])
}

for _, f := range factMD {
err := writeFactsToGraphql(err, f)
if err != nil {
return err
}
}

var factsUIUrl = fmt.Sprintf("%s/projects/%s/%s/facts", lagoonUIEndpoint, projectName, fmt.Sprintf("%s-%s", projectName, environmentName))
log.Printf("Successfully added facts to %s:%s \n %s", projectName, environmentName, factsUIUrl)

return nil
}

func writeFactsToGraphql(err error, facts []GatheredFact) error {
client, err := getGraphqlClient()
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -75,10 +101,6 @@ func Writefacts(projectName string, environmentName string, facts []GatheredFact
if err := client.Run(ctx, req, &addFactMutation); err != nil {
log.Fatal(err)
}

var factsUIUrl = fmt.Sprintf("%s/projects/%s/%s/facts", lagoonUIEndpoint, projectName, fmt.Sprintf("%s-%s", projectName, environmentName))
log.Printf("Successfully added facts to %s:%s \n %s", projectName, environmentName, factsUIUrl)

return nil
}

Expand Down

0 comments on commit 30a47d2

Please sign in to comment.