@@ -6,12 +6,15 @@ import (
66
77 "github.com/ipfs/go-cid"
88 "github.com/ipfs/go-datastore"
9+ "github.com/ipfs/go-datastore/query"
10+ logging "github.com/ipfs/go-log/v2"
911 "github.com/textileio/powergate/ffs"
1012 "github.com/textileio/powergate/ffs/scheduler"
1113)
1214
1315var (
1416 dsBase = datastore .NewKey ("cistore" )
17+ log = logging .Logger ("ffs-sched-cistore" )
1518)
1619
1720// Store is an Datastore implementation of CidInfoStore
@@ -59,6 +62,32 @@ func (s *Store) Put(ci ffs.CidInfo) error {
5962 return nil
6063}
6164
65+ // Query returns a list of CidInfo
66+ func (s * Store ) Query (selector func (ffs.CidInfo ) bool ) ([]ffs.CidInfo , error ) {
67+ q := query.Query {Prefix : "" }
68+ res , err := s .ds .Query (q )
69+ if err != nil {
70+ return nil , fmt .Errorf ("executing query in datastore: %s" , err )
71+ }
72+ defer func () {
73+ if err := res .Close (); err != nil {
74+ log .Errorf ("closing query result: %s" , err )
75+ }
76+ }()
77+
78+ var infos []ffs.CidInfo
79+ for r := range res .Next () {
80+ var i ffs.CidInfo
81+ if err := json .Unmarshal (r .Value , & i ); err != nil {
82+ return nil , fmt .Errorf ("unmarshalling push config action in query: %s" , err )
83+ }
84+ if selector (i ) {
85+ infos = append (infos , i )
86+ }
87+ }
88+ return infos , nil
89+ }
90+
6291func makeKey (c cid.Cid ) datastore.Key {
6392 return dsBase .ChildString (c .String ())
6493}
0 commit comments