-
Notifications
You must be signed in to change notification settings - Fork 66
/
init.go
44 lines (37 loc) · 1.05 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"github.com/application-research/estuary/config"
"github.com/application-research/estuary/util"
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
"gorm.io/gorm"
)
type Initializer struct {
cfg *config.Node
db *gorm.DB
trackingBstore *util.TrackingBlockstore
}
func (init *Initializer) Config() *config.Node {
return init.cfg
}
func (init *Initializer) BlockstoreWrap(bs blockstore.Blockstore) (blockstore.Blockstore, error) {
init.trackingBstore = util.NewTrackingBlockstore(bs, init.db)
return init.trackingBstore, nil
}
func (init *Initializer) KeyProviderFunc(rpctx context.Context) (<-chan cid.Cid, error) {
out := make(chan cid.Cid)
go func() {
defer close(out)
var contents []util.Content
if err := init.db.Where("active = ?", true).FindInBatches(&contents, util.DefaultBatchSize, func(tx *gorm.DB, batch int) error {
for _, c := range contents {
out <- c.Cid.CID
}
return nil
}).Error; err != nil {
log.Error(err)
}
}()
return out, nil
}