MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / View

Method View

base/collection_view.go:192–238  ·  view source on GitHub ↗
(ctx context.Context, ddoc, name string, params map[string]interface{})

Source from the content-addressed store, hash-verified

190}
191
192func (c *Collection) View(ctx context.Context, ddoc, name string, params map[string]interface{}) (sgbucket.ViewResult, error) {
193 var viewResult sgbucket.ViewResult
194 gocbViewResult, err := c.executeViewQuery(ctx, ddoc, name, params)
195 if err != nil {
196 return viewResult, err
197 }
198
199 if gocbViewResult != nil {
200 viewResultIterator := &gocbRawIterator{
201 rawResult: gocbViewResult,
202 concurrentQueryOpLimitChan: c.Bucket.queryOps,
203 }
204 for {
205 viewRow := sgbucket.ViewRow{}
206 if gotRow := viewResultIterator.Next(ctx, &viewRow); gotRow == false {
207 break
208 }
209 viewResult.Rows = append(viewResult.Rows, &viewRow)
210 }
211
212 // Check for errors
213 err = gocbViewResult.Err()
214 if err != nil {
215 viewErr := sgbucket.ViewError{
216 Reason: err.Error(),
217 }
218 viewResult.Errors = append(viewResult.Errors, viewErr)
219 }
220
221 viewMeta, err := unmarshalViewMetadata(gocbViewResult)
222 if err != nil {
223 WarnfCtx(ctx, "Unable to type get metadata for gocb ViewResult - the total rows count will be missing.")
224 } else {
225 viewResult.TotalRows = viewMeta.TotalRows
226 }
227 _ = viewResultIterator.Close()
228
229 }
230
231 // Indicate the view response contained partial errors so consumers can determine
232 // if the result is valid to their particular use-case (see SG issue #2383)
233 if len(viewResult.Errors) > 0 {
234 return viewResult, ErrPartialViewErrors
235 }
236
237 return viewResult, nil
238}
239
240func unmarshalViewMetadata(viewResult *gocb.ViewResultRaw) (viewMetadata, error) {
241 var viewMeta viewMetadata

Callers 3

TestViewFunction · 0.45
handleDumpMethod · 0.45
QueryDesignDocMethod · 0.45

Calls 7

executeViewQueryMethod · 0.95
NextMethod · 0.95
CloseMethod · 0.95
unmarshalViewMetadataFunction · 0.85
WarnfCtxFunction · 0.85
ErrMethod · 0.80
ErrorMethod · 0.45

Tested by 1

TestViewFunction · 0.36