MCPcopy
hub / github.com/dgraph-io/dgraph / Process

Method Process

query/query.go:3046–3085  ·  view source on GitHub ↗

Process handles a query request.

(ctx context.Context)

Source from the content-addressed store, hash-verified

3044
3045// Process handles a query request.
3046func (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.
3088func filterTypesForNamespace(namespace uint64, types []*pb.TypeUpdate) []*pb.TypeUpdate {

Callers 2

processQueryFunction · 0.95
startTaskAtTsMethod · 0.45

Calls 9

ProcessQueryMethod · 0.95
ExtractNamespaceFunction · 0.92
NamespaceAttrListFunction · 0.92
GetSchemaOverNetworkFunction · 0.92
GetTypesFunction · 0.92
IsRootNsOperationFunction · 0.92
calculateMetricsFunction · 0.85
filterTypesForNamespaceFunction · 0.85

Tested by

no test coverage detected