MCPcopy Create free account
hub / github.com/couchbaselabs/cbgb / execViewMapFunction

Method execViewMapFunction

view_refresh.go:156–194  ·  view source on GitHub ↗

Executes the map function on an item.

(ddocId string, ddoc *DDoc,
	viewId string, view *View, i *item)

Source from the content-addressed store, hash-verified

154
155// Executes the map function on an item.
156func (v *VBucket) execViewMapFunction(ddocId string, ddoc *DDoc,
157 viewId string, view *View, i *item) (ViewRows, error) {
158 pvmf, err := view.GetViewMapFunction()
159 if err != nil {
160 return nil, err
161 }
162 docId := string(i.key)
163 docType := "json"
164 var doc interface{}
165 err = json.Unmarshal(i.data, &doc)
166 if err != nil {
167 doc = base64.StdEncoding.EncodeToString(i.data)
168 docType = "base64"
169 }
170 odoc, err := OttoFromGo(pvmf.otto, doc)
171 if err != nil {
172 return nil, err
173 }
174 meta := map[string]interface{}{
175 "id": docId,
176 "type": docType,
177 }
178 ometa, err := OttoFromGo(pvmf.otto, meta)
179 if err != nil {
180 return nil, err
181 }
182 _, err = pvmf.mapf.Call(pvmf.mapf, odoc, ometa)
183 if err != nil {
184 return nil, err
185 }
186 emits, err := pvmf.restartEmits()
187 if err != nil {
188 return nil, err
189 }
190 for _, emit := range emits {
191 emit.Id = docId
192 }
193 return emits, nil
194}
195
196func (v *VBucket) getViewsStore() (res *bucketstore, err error) {
197 v.Apply(func() {

Callers 1

viewsRefreshItemMethod · 0.95

Calls 2

OttoFromGoFunction · 0.85
GetViewMapFunctionMethod · 0.80

Tested by

no test coverage detected