Function
addBatch
(db *metadb.DB, toAdd []*T, resourceType string)
Source from the content-addressed store, hash-verified
| 24 | ) |
| 25 | |
| 26 | func addBatch[T constraint.OperateBatchModel](db *metadb.DB, toAdd []*T, resourceType string) error { |
| 27 | count := len(toAdd) |
| 28 | offset := 1000 |
| 29 | pages := count/offset + 1 |
| 30 | if count%offset == 0 { |
| 31 | pages = count / offset |
| 32 | } |
| 33 | for i := 0; i < pages; i++ { |
| 34 | start := i * offset |
| 35 | end := (i + 1) * offset |
| 36 | if end > count { |
| 37 | end = count |
| 38 | } |
| 39 | oneP := toAdd[start:end] |
| 40 | err := db.Clauses(clause.Returning{}).Create(&oneP).Error |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | log.Infof("add %d %s success", len(oneP), resourceType, db.LogPrefixORGID) |
| 45 | } |
| 46 | return nil |
| 47 | } |
Tested by
no test coverage detected