github.com/koko1123/flow-go-1@v0.29.6/storage/badger/computation_result.go (about)

     1  package badger
     2  
     3  import (
     4  	"github.com/dgraph-io/badger/v3"
     5  
     6  	"github.com/koko1123/flow-go-1/model/flow"
     7  	"github.com/koko1123/flow-go-1/storage/badger/operation"
     8  )
     9  
    10  type ComputationResultUploadStatus struct {
    11  	db *badger.DB
    12  }
    13  
    14  func NewComputationResultUploadStatus(db *badger.DB) *ComputationResultUploadStatus {
    15  	return &ComputationResultUploadStatus{
    16  		db: db,
    17  	}
    18  }
    19  
    20  func (c *ComputationResultUploadStatus) Upsert(blockID flow.Identifier,
    21  	wasUploadCompleted bool) error {
    22  	return operation.RetryOnConflict(c.db.Update, func(btx *badger.Txn) error {
    23  		return operation.UpsertComputationResultUploadStatus(blockID, wasUploadCompleted)(btx)
    24  	})
    25  }
    26  
    27  func (c *ComputationResultUploadStatus) GetIDsByUploadStatus(targetUploadStatus bool) ([]flow.Identifier, error) {
    28  	ids := make([]flow.Identifier, 0)
    29  	err := c.db.View(operation.GetBlockIDsByStatus(&ids, targetUploadStatus))
    30  	return ids, err
    31  }
    32  
    33  func (c *ComputationResultUploadStatus) ByID(computationResultID flow.Identifier) (bool, error) {
    34  	var ret bool
    35  	err := c.db.View(func(btx *badger.Txn) error {
    36  		return operation.GetComputationResultUploadStatus(computationResultID, &ret)(btx)
    37  	})
    38  	if err != nil {
    39  		return false, err
    40  	}
    41  
    42  	return ret, nil
    43  }
    44  
    45  func (c *ComputationResultUploadStatus) Remove(computationResultID flow.Identifier) error {
    46  	return operation.RetryOnConflict(c.db.Update, func(btx *badger.Txn) error {
    47  		return operation.RemoveComputationResultUploadStatus(computationResultID)(btx)
    48  	})
    49  }