GetPermanodesWithAttr returns permanodes with attribute req.Attr having the req.Value as a value. See WithAttrRequest for more details about the query.
(req *WithAttrRequest)
| 573 | // having the req.Value as a value. |
| 574 | // See WithAttrRequest for more details about the query. |
| 575 | func (h *Handler) GetPermanodesWithAttr(req *WithAttrRequest) (*WithAttrResponse, error) { |
| 576 | ctx := context.TODO() |
| 577 | |
| 578 | h.index.RLock() |
| 579 | defer h.index.RUnlock() |
| 580 | |
| 581 | ch := make(chan blob.Ref, buffered) |
| 582 | errch := make(chan error, 1) |
| 583 | go func() { |
| 584 | signer := req.Signer |
| 585 | if !signer.Valid() { |
| 586 | signer = h.owner.BlobRef() |
| 587 | } |
| 588 | errch <- h.index.SearchPermanodesWithAttr(ctx, ch, |
| 589 | &camtypes.PermanodeByAttrRequest{ |
| 590 | Attribute: req.Attr, |
| 591 | Query: req.Value, |
| 592 | Signer: signer, |
| 593 | FuzzyMatch: req.Fuzzy, |
| 594 | MaxResults: req.N, |
| 595 | At: req.At, |
| 596 | }) |
| 597 | }() |
| 598 | |
| 599 | dr := h.NewDescribeRequest() |
| 600 | |
| 601 | var withAttr []*WithAttrItem |
| 602 | for res := range ch { |
| 603 | dr.StartDescribe(ctx, res, 2) |
| 604 | withAttr = append(withAttr, &WithAttrItem{ |
| 605 | Permanode: res, |
| 606 | }) |
| 607 | } |
| 608 | |
| 609 | metaMap, err := dr.metaMap() |
| 610 | if err != nil { |
| 611 | return nil, err |
| 612 | } |
| 613 | |
| 614 | if err := <-errch; err != nil { |
| 615 | return nil, err |
| 616 | } |
| 617 | |
| 618 | res := &WithAttrResponse{ |
| 619 | WithAttr: withAttr, |
| 620 | Meta: metaMap, |
| 621 | } |
| 622 | return res, nil |
| 623 | } |
| 624 | |
| 625 | // servePermanodesWithAttr uses the indexer to search for the permanodes matching |
| 626 | // the request. |
no test coverage detected