github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/chunks/handle_counts.go (about) 1 package chunksPkg 2 3 import ( 4 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 5 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" 6 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest" 7 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/pinning" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk" 11 ) 12 13 func (opts *ChunksOptions) HandleCounts(rCtx *output.RenderCtx, blockNums []base.Blknum) error { 14 chain := opts.Globals.Chain 15 testMode := opts.Globals.TestMode 16 17 fetchData := func(modelChan chan types.Modeler, errorChan chan error) { 18 var counter types.Count 19 vFunc := func(path string, vP any) (bool, error) { 20 isBloom := path == index.ToBloomPath(path) 21 isIndex := path == index.ToIndexPath(path) 22 if isBloom || isIndex { 23 counter.Count++ 24 } 25 return true, nil 26 } 27 28 switch opts.Mode { 29 case "blooms": 30 path := walk.GetRootPathFromCacheType(chain, walk.Index_Bloom) 31 _ = walk.ForEveryFileInFolder(path, vFunc, nil) 32 case "index", "stats": 33 path := walk.GetRootPathFromCacheType(chain, walk.Index_Final) 34 _ = walk.ForEveryFileInFolder(path, vFunc, nil) 35 case "manifest": 36 man, _ := manifest.LoadManifest(chain, opts.PublisherAddr, sourceMap[opts.Remote]) 37 counter.Count = uint64(len(man.Chunks)) 38 case "pins": 39 counter.Count = pinning.CountPins(chain, "pinned") 40 } 41 42 if testMode { 43 counter.Count = 100 44 } 45 46 modelChan <- &counter 47 } 48 49 return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts()) 50 }