populateNamespace fetches the schema and extracts the information about the existing namespaces.
(ctx context.Context, dc *dgo.Dgraph, singleNsOp bool)
| 627 | |
| 628 | // populateNamespace fetches the schema and extracts the information about the existing namespaces. |
| 629 | func (l *loader) populateNamespaces(ctx context.Context, dc *dgo.Dgraph, singleNsOp bool) error { |
| 630 | if singleNsOp { |
| 631 | // The below schema query returns the predicates without the namespace if context does not |
| 632 | // have the galaxy operation set. As we are not loading data across namespaces, so existence |
| 633 | // of namespace is verified when the user logs in. |
| 634 | l.namespaces[opt.namespaceToLoad] = struct{}{} |
| 635 | return nil |
| 636 | } |
| 637 | |
| 638 | txn := dc.NewTxn() |
| 639 | defer func() { |
| 640 | if err := txn.Discard(ctx); err != nil { |
| 641 | glog.Warningf("error in discarding txn: %v", err) |
| 642 | } |
| 643 | }() |
| 644 | |
| 645 | res, err := txn.Query(ctx, "schema {}") |
| 646 | if err != nil { |
| 647 | return err |
| 648 | } |
| 649 | |
| 650 | var sch Schema |
| 651 | err = json.Unmarshal(res.GetJson(), &sch) |
| 652 | if err != nil { |
| 653 | return err |
| 654 | } |
| 655 | |
| 656 | for _, pred := range sch.Predicates { |
| 657 | ns := x.ParseNamespace(pred.Predicate) |
| 658 | l.namespaces[ns] = struct{}{} |
| 659 | } |
| 660 | return nil |
| 661 | } |
| 662 | |
| 663 | func run() error { |
| 664 | creds := z.NewSuperFlag(Live.Conf.GetString("creds")).MergeAndCheckDefault(x.DefaultCreds) |
no test coverage detected