Process handles a query request.
(ctx context.Context)
| 3044 | |
| 3045 | // Process handles a query request. |
| 3046 | func (req *Request) Process(ctx context.Context) (er ExecutionResult, err error) { |
| 3047 | err = req.ProcessQuery(ctx) |
| 3048 | if err != nil { |
| 3049 | return er, err |
| 3050 | } |
| 3051 | er.Subgraphs = req.Subgraphs |
| 3052 | // calculate metrics. |
| 3053 | metrics := make(map[string]uint64) |
| 3054 | for _, sg := range er.Subgraphs { |
| 3055 | calculateMetrics(sg, metrics) |
| 3056 | } |
| 3057 | er.Metrics = metrics |
| 3058 | namespace, err := x.ExtractNamespace(ctx) |
| 3059 | if err != nil { |
| 3060 | return er, errors.Wrapf(err, "While processing query") |
| 3061 | } |
| 3062 | schemaProcessingStart := time.Now() |
| 3063 | if req.DqlQuery.Schema != nil { |
| 3064 | preds := x.NamespaceAttrList(namespace, req.DqlQuery.Schema.Predicates) |
| 3065 | req.DqlQuery.Schema.Predicates = preds |
| 3066 | if er.SchemaNode, err = worker.GetSchemaOverNetwork(ctx, req.DqlQuery.Schema); err != nil { |
| 3067 | return er, errors.Wrapf(err, "while fetching schema") |
| 3068 | } |
| 3069 | typeNames := x.NamespaceAttrList(namespace, req.DqlQuery.Schema.Types) |
| 3070 | req.DqlQuery.Schema.Types = typeNames |
| 3071 | if er.Types, err = worker.GetTypes(ctx, req.DqlQuery.Schema); err != nil { |
| 3072 | return er, errors.Wrapf(err, "while fetching types") |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | if !x.IsRootNsOperation(ctx) { |
| 3077 | // Filter the schema nodes for the given namespace. |
| 3078 | er.SchemaNode = filterSchemaNodeForNamespace(namespace, er.SchemaNode) |
| 3079 | // Filter the types for the given namespace. |
| 3080 | er.Types = filterTypesForNamespace(namespace, er.Types) |
| 3081 | } |
| 3082 | req.Latency.Processing += time.Since(schemaProcessingStart) |
| 3083 | |
| 3084 | return er, nil |
| 3085 | } |
| 3086 | |
| 3087 | // filterTypesForNamespace filters types for the given namespace. |
| 3088 | func filterTypesForNamespace(namespace uint64, types []*pb.TypeUpdate) []*pb.TypeUpdate { |
no test coverage detected