2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-10-01 11:49:10 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2020-09-28 15:11:11 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-09-22 06:51:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/localstore"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/search/query"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type localStream struct {
|
|
|
|
query query.Query
|
|
|
|
|
|
|
|
storage *localstore.Storage
|
2020-10-01 11:49:10 +00:00
|
|
|
|
|
|
|
cid *container.ID
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 15:11:11 +00:00
|
|
|
func (s *localStream) stream(ctx context.Context, ch chan<- []*objectSDK.ID) error {
|
2020-10-29 17:16:49 +00:00
|
|
|
fs := s.query.ToSearchFilters()
|
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, s.cid)
|
2020-09-28 15:11:11 +00:00
|
|
|
|
2020-10-29 17:16:49 +00:00
|
|
|
addrList, err := s.storage.Select(fs)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not select objects from local storage", s)
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 17:16:49 +00:00
|
|
|
idList := make([]*objectSDK.ID, 0, len(addrList))
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2020-10-29 17:16:49 +00:00
|
|
|
for i := range addrList {
|
2020-11-16 09:43:52 +00:00
|
|
|
idList = append(idList, addrList[i].ObjectID())
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 17:16:49 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
case ch <- idList:
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|