github.com/quay/claircore@v1.5.28/indexer/controller/reduce.go (about)

     1  package controller
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/quay/zlog"
     7  
     8  	"github.com/quay/claircore"
     9  	"github.com/quay/claircore/indexer"
    10  )
    11  
    12  // reduce determines which layers should be fetched/scanned and returns these layers
    13  func reduce(ctx context.Context, store indexer.Store, scnrs indexer.VersionedScanners, layers []*claircore.Layer) ([]*claircore.Layer, error) {
    14  	do := []*claircore.Layer{}
    15  	for _, l := range layers {
    16  		for _, scnr := range scnrs {
    17  			ok, err := store.LayerScanned(ctx, l.Hash, scnr)
    18  			if err != nil {
    19  				zlog.Debug(ctx).
    20  					Stringer("layer", l.Hash).
    21  					Err(err).
    22  					Msg("unable to lookup layer")
    23  				return nil, err
    24  			}
    25  			if !ok {
    26  				do = append(do, l)
    27  				break
    28  			}
    29  		}
    30  	}
    31  	return do, nil
    32  }