getSchema iterates over all predicates and populates the asked fields, if list of predicates is not specified, then all the predicates belonging to the group are returned
(ctx context.Context, s *pb.SchemaRequest)
| 31 | // predicates is not specified, then all the predicates belonging to the group |
| 32 | // are returned |
| 33 | func getSchema(ctx context.Context, s *pb.SchemaRequest) (*pb.SchemaResult, error) { |
| 34 | _, span := otel.Tracer("").Start(ctx, "worker.getSchema") |
| 35 | defer span.End() |
| 36 | |
| 37 | var result pb.SchemaResult |
| 38 | var predicates []string |
| 39 | var fields []string |
| 40 | if len(s.Predicates) > 0 { |
| 41 | predicates = s.Predicates |
| 42 | } else { |
| 43 | predicates = schema.State().Predicates() |
| 44 | } |
| 45 | if len(s.Fields) > 0 { |
| 46 | fields = s.Fields |
| 47 | } else { |
| 48 | fields = []string{"type", "index", "tokenizer", "reverse", "count", "list", "upsert", "unique", |
| 49 | "lang", "noconflict", "vector_specs"} |
| 50 | } |
| 51 | |
| 52 | myGid := groups().groupId() |
| 53 | for _, attr := range predicates { |
| 54 | // This can happen after a predicate is moved. We don't delete predicate from schema state |
| 55 | // immediately. So lets ignore this predicate. |
| 56 | gid, err := groups().BelongsToReadOnly(attr, 0) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | if myGid != gid { |
| 61 | continue |
| 62 | } |
| 63 | |
| 64 | if schemaNode := populateSchema(attr, fields); schemaNode != nil { |
| 65 | result.Schema = append(result.Schema, schemaNode) |
| 66 | } |
| 67 | } |
| 68 | return &result, nil |
| 69 | } |
| 70 | |
| 71 | // populateSchema returns the information of asked fields for given attribute |
| 72 | func populateSchema(attr string, fields []string) *pb.SchemaNode { |
no test coverage detected