Query handles queries or mutations
(ctx context.Context, req *api.Request)
| 1357 | |
| 1358 | // Query handles queries or mutations |
| 1359 | func (s *Server) QueryNoGrpc(ctx context.Context, req *api.Request) (*api.Response, error) { |
| 1360 | ctx = x.AttachJWTNamespace(ctx) |
| 1361 | if x.WorkerConfig.AclEnabled && req.GetStartTs() != 0 { |
| 1362 | // A fresh StartTs is assigned if it is 0. |
| 1363 | ns, err := x.ExtractNamespace(ctx) |
| 1364 | if err != nil { |
| 1365 | return nil, err |
| 1366 | } |
| 1367 | if req.GetHash() != getHash(ns, req.GetStartTs()) { |
| 1368 | return nil, x.ErrHashMismatch |
| 1369 | } |
| 1370 | } |
| 1371 | // Add a timeout for queries which don't have a deadline set. We don't want to |
| 1372 | // apply a timeout if it's a mutation, that's currently handled by flag |
| 1373 | // "txn-abort-after". |
| 1374 | if req.GetMutations() == nil && x.Config.QueryTimeout != 0 { |
| 1375 | if d, _ := ctx.Deadline(); d.IsZero() { |
| 1376 | var cancel context.CancelFunc |
| 1377 | ctx, cancel = context.WithTimeout(ctx, x.Config.QueryTimeout) |
| 1378 | defer cancel() |
| 1379 | } |
| 1380 | } |
| 1381 | return s.doQuery(ctx, &Request{req: req, doAuth: getAuthMode(ctx)}) |
| 1382 | } |
| 1383 | |
| 1384 | func (s *Server) QueryNoAuth(ctx context.Context, req *api.Request) (*api.Response, error) { |
| 1385 | return s.doQuery(ctx, &Request{req: req, doAuth: NoAuthorize}) |
no test coverage detected