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

Function N1QLQueryWithStats

db/query.go:373–400  ·  view source on GitHub ↗

N1QlQueryWithStats is a wrapper for gocbBucket.Query that performs additional diagnostic processing (expvars, slow query logging)

(ctx context.Context, dataStore base.DataStore, queryName string, statement string, params map[string]interface{}, consistency base.ConsistencyMode, adhoc bool, dbStats *base.DbStats, slowQueryWarningThreshold time.Duration)

Source from the content-addressed store, hash-verified

371
372// N1QlQueryWithStats is a wrapper for gocbBucket.Query that performs additional diagnostic processing (expvars, slow query logging)
373func N1QLQueryWithStats(ctx context.Context, dataStore base.DataStore, queryName string, statement string, params map[string]interface{}, consistency base.ConsistencyMode, adhoc bool, dbStats *base.DbStats, slowQueryWarningThreshold time.Duration) (results sgbucket.QueryResultIterator, err error) {
374
375 startTime := time.Now()
376 if threshold := slowQueryWarningThreshold; threshold > 0 {
377 defer base.SlowQueryLog(ctx, startTime, threshold, "N1QL Query(%q)", queryName)
378 }
379
380 n1QLStore, ok := base.AsN1QLStore(dataStore)
381 if !ok {
382 return nil, errors.New("Cannot perform N1QL query on non-Couchbase bucket.")
383 }
384
385 results, err = n1QLStore.Query(ctx, statement, params, consistency, adhoc)
386
387 if len(queryName) > 0 {
388 queryStat := dbStats.Query(queryName)
389 if queryStat == nil {
390 // This panic is more recognizable than the one that will otherwise occur below
391 panic(fmt.Sprintf("DbStats has no entry for query %q", queryName))
392 }
393 if err != nil {
394 queryStat.QueryErrorCount.Add(1)
395 }
396 queryStat.QueryCount.Add(1)
397 queryStat.QueryTime.Add(time.Since(startTime).Nanoseconds())
398 }
399 return results, err
400}
401
402// ViewQueryWithStats is a wrapper for gocbBucket.Query that performs additional diagnostic processing (expvars, slow query logging)
403func (context *DatabaseContext) ViewQueryWithStats(ctx context.Context, dataStore base.DataStore, ddoc string, viewName string, params map[string]interface{}) (results sgbucket.QueryResultIterator, err error) {

Callers 10

IterateMethod · 0.92
QueryAccessMethod · 0.85
QueryRoleAccessMethod · 0.85
QueryChannelsMethod · 0.85
QueryPrincipalsMethod · 0.85
QueryUsersMethod · 0.85
QueryRolesMethod · 0.85
QueryAllRolesMethod · 0.85
QueryAllDocsMethod · 0.85
QueryTombstonesMethod · 0.85

Calls 5

SlowQueryLogFunction · 0.92
AsN1QLStoreFunction · 0.92
QueryMethod · 0.65
AddMethod · 0.45
SinceMethod · 0.45

Tested by

no test coverage detected