Query to compute the set of channels granted to the specified user via the Sync Function
(ctx context.Context, username string)
| 426 | |
| 427 | // Query to compute the set of channels granted to the specified user via the Sync Function |
| 428 | func (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. |
| 449 | func (c *DatabaseCollection) buildAccessQuery(username string) string { |