github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/chunks/handle_stats.go (about) 1 // Copyright 2021 The TrueBlocks Authors. All rights reserved. 2 // Use of this source code is governed by a license that can 3 // be found in the LICENSE file. 4 5 package chunksPkg 6 7 import ( 8 "fmt" 9 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 11 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" 12 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 13 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 14 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk" 15 ) 16 17 func (opts *ChunksOptions) HandleStats(rCtx *output.RenderCtx, blockNums []base.Blknum) error { 18 chain := opts.Globals.Chain 19 fetchData := func(modelChan chan types.Modeler, errorChan chan error) { 20 showFinalizedStats := func(walker *walk.CacheWalker, path string, first bool) (bool, error) { 21 if path != index.ToBloomPath(path) { 22 return false, fmt.Errorf("should not happen in showFinalizedStats") 23 } 24 25 if s, err := GetChunkStats(chain, path); err != nil { 26 return false, err 27 28 } else { 29 modelChan <- &s 30 } 31 32 return true, nil 33 } 34 35 walker := walk.NewCacheWalker( 36 chain, 37 opts.Globals.TestMode, 38 100, /* maxTests */ 39 showFinalizedStats, 40 ) 41 42 if err := walker.WalkBloomFilters(blockNums); err != nil { 43 errorChan <- err 44 rCtx.Cancel() 45 } 46 } 47 48 return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts()) 49 }