MCPcopy
hub / github.com/andeya/pholcus / Exec

Method Exec

common/mgo/insert.go:21–63  ·  view source on GitHub ↗
(resultPtr interface{})

Source from the content-addressed store, hash-verified

19)
20
21func (i *Insert) Exec(resultPtr interface{}) (r result.Result[any]) {
22 defer r.Catch()
23 var (
24 resultPtr2 = new([]string)
25 count = len(i.Docs)
26 docs = make([]interface{}, count)
27 )
28 if resultPtr != nil {
29 resultPtr2 = resultPtr.(*[]string)
30 }
31 *resultPtr2 = make([]string, count)
32
33 Call(func(src pool.Src) error {
34 c := getSessionFunc(src).DB(i.Database).C(i.Collection)
35 for i, doc := range i.Docs {
36 var _id string
37 if doc["_id"] == nil || doc["_id"] == interface{}("") || doc["_id"] == interface{}(0) {
38 objId := bson.NewObjectId()
39 _id = objId.Hex()
40 doc["_id"] = objId
41 } else {
42 _id = doc["_id"].(string)
43 }
44
45 if resultPtr != nil {
46 (*resultPtr2)[i] = _id
47 }
48 docs[i] = doc
49 }
50 loop := count / MaxLen
51 for i := 0; i < loop; i++ {
52 err := c.Insert(docs[i*MaxLen : (i+1)*MaxLen]...)
53 if err != nil {
54 return err
55 }
56 }
57 if count%MaxLen == 0 {
58 return nil
59 }
60 return c.Insert(docs[loop*MaxLen:]...)
61 }).Unwrap()
62 return result.Ok[any](nil)
63}

Callers

nothing calls this directly

Calls 5

CallFunction · 0.85
UnwrapMethod · 0.80
CMethod · 0.65
DBMethod · 0.65
InsertMethod · 0.65

Tested by

no test coverage detected