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

Method QueryAccess

db/query.go:428–446  ·  view source on GitHub ↗

Query to compute the set of channels granted to the specified user via the Sync Function

(ctx context.Context, username string)

Source from the content-addressed store, hash-verified

426
427// Query to compute the set of channels granted to the specified user via the Sync Function
428func (c *DatabaseCollection) QueryAccess(ctx context.Context, username string) (sgbucket.QueryResultIterator, error) {
429
430 // View Query
431 if c.useViews() {
432 opts := map[string]interface{}{"stale": false, "key": username}
433 return c.dbCtx.ViewQueryWithStats(ctx, c.dataStore, DesignDocSyncGateway(), ViewAccess, opts)
434 }
435
436 // N1QL Query
437 if username == "" {
438 base.WarnfCtx(ctx, "QueryAccess called with empty username - returning empty result iterator")
439 return &EmptyResultIterator{}, nil
440 }
441 accessQueryStatement := c.buildAccessQuery(username)
442 params := make(map[string]interface{}, 0)
443 params[QueryParamUserName] = username
444
445 return N1QLQueryWithStats(ctx, c.dataStore, QueryAccess.name, accessQueryStatement, params, base.RequestPlus, QueryAccess.adhoc, c.dbStats(), c.slowQueryWarningThreshold())
446}
447
448// Builds the query statement for an access N1QL query.
449func (c *DatabaseCollection) buildAccessQuery(username string) string {

Callers 2

TestAccessQueryFunction · 0.80

Calls 8

useViewsMethod · 0.95
buildAccessQueryMethod · 0.95
dbStatsMethod · 0.95
WarnfCtxFunction · 0.92
DesignDocSyncGatewayFunction · 0.85
N1QLQueryWithStatsFunction · 0.85
ViewQueryWithStatsMethod · 0.80

Tested by 1

TestAccessQueryFunction · 0.64