github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/when/handle_decache.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 whenPkg
     6  
     7  import (
     8  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/decache"
     9  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
    10  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
    11  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk"
    12  )
    13  
    14  func (opts *WhenOptions) HandleDecache(rCtx *output.RenderCtx) error {
    15  	itemsToRemove, err := decache.LocationsFromBlocks(opts.Conn, opts.BlockIds)
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
    21  		showProgress := opts.Globals.ShowProgress()
    22  		if msg, err := decache.Decache(opts.Conn, itemsToRemove, showProgress, walk.Cache_Blocks); err != nil {
    23  			errorChan <- err
    24  		} else {
    25  			s := types.Message{
    26  				Msg: msg,
    27  			}
    28  			modelChan <- &s
    29  		}
    30  	}
    31  
    32  	opts.Globals.NoHeader = true
    33  	return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts())
    34  }