Optimize the apiSubmit function to ensure that it doesn't lead to errors from large insertions

This commit is contained in:
David Dworken
2022-11-26 10:31:43 -08:00
parent 8d87110405
commit c603537137
4 changed files with 28 additions and 20 deletions

View File

@ -91,3 +91,15 @@ type Feedback struct {
Date time.Time `json:"date" gorm:"not null"`
Feedback string `json:"feedback"`
}
func Chunks[k any](slice []k, chunkSize int) [][]k {
var chunks [][]k
for i := 0; i < len(slice); i += chunkSize {
end := i + chunkSize
if end > len(slice) {
end = len(slice)
}
chunks = append(chunks, slice[i:end])
}
return chunks
}