MCPcopy Index your code
hub / github.com/apache/devlake / NewBatchSave

Function NewBatchSave

backend/helpers/pluginhelper/api/batch_save.go:51–78  ·  view source on GitHub ↗

NewBatchSave creates a new BatchSave instance

(basicRes context.BasicRes, slotType reflect.Type, size int, tableName ...string)

Source from the content-addressed store, hash-verified

49
50// NewBatchSave creates a new BatchSave instance
51func NewBatchSave(basicRes context.BasicRes, slotType reflect.Type, size int, tableName ...string) (*BatchSave, errors.Error) {
52 if slotType.Kind() != reflect.Ptr {
53 panic(errors.Default.New("slotType must be a pointer"))
54 }
55 db := basicRes.GetDal()
56 primaryKey := db.GetPrimaryKeyFields(slotType)
57 // check if it has primaryKey
58 if len(primaryKey) == 0 {
59 return nil, errors.Default.New(fmt.Sprintf("%s no primary key", slotType.String()))
60 }
61 tn := ""
62 if len(tableName) == 1 {
63 tn = tableName[0]
64 }
65
66 logger := basicRes.GetLogger().Nested(slotType.String())
67 return &BatchSave{
68 basicRes: basicRes,
69 log: logger,
70 db: db,
71 slotType: slotType,
72 slots: reflect.MakeSlice(reflect.SliceOf(slotType), size, size),
73 size: size,
74 valueIndex: make(map[string]int),
75 primaryKey: primaryKey,
76 tableName: tn,
77 }, nil
78}
79
80// Add record to cache. BatchSave would flush them into Database when cache is max out
81func (c *BatchSave) Add(slot interface{}) errors.Error {

Callers 2

ForTypeMethod · 0.85
NewGraphqlCollectorFunction · 0.85

Calls 6

NewMethod · 0.65
GetDalMethod · 0.65
GetPrimaryKeyFieldsMethod · 0.65
NestedMethod · 0.65
GetLoggerMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected