Skip to content

Commit

Permalink
feat: rm GetDealsByPieceStatus
Browse files Browse the repository at this point in the history
from StorageDealRepo
  • Loading branch information
LinZexiao committed Sep 23, 2022
1 parent 44bb2f8 commit d2115b7
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 58 deletions.
16 changes: 0 additions & 16 deletions models/badger/storage_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,6 @@ func TestStorageDeal(t *testing.T) {
assert.Equal(t, dealCases[0], *res[0])
})

t.Run("GetDealsByPieceStatus", func(t *testing.T) {
t.Run("With Provider", func(t *testing.T) {
res, err := r.GetDealsByPieceStatus(ctx, dealCases[0].Proposal.Provider, dealCases[0].PieceStatus)
assert.NoError(t, err)
assert.Equal(t, 1, len(res))
assert.Equal(t, dealCases[0], *res[0])
})

t.Run("Without Provider", func(t *testing.T) {
res, err := r.GetDealsByPieceStatus(ctx, address.Undef, dealCases[0].PieceStatus)
assert.NoError(t, err)
assert.Equal(t, 1, len(res))
assert.Equal(t, dealCases[0], *res[0])
})
})

t.Run("GetDealsByPieceStatusAndDealStatus", func(t *testing.T) {
t.Run("With DealStatus", func(t *testing.T) {
res, err := r.GetDealsByPieceStatusAndDealStatus(ctx, dealCases[0].Proposal.Provider, dealCases[0].PieceStatus, dealCases[0].State)
Expand Down
14 changes: 0 additions & 14 deletions models/mysql/storage_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,20 +516,6 @@ func (sdr *storageDealRepo) GetDealByDealID(ctx context.Context, mAddr address.A
return toStorageDeal(dbDeal)
}

func (sdr *storageDealRepo) GetDealsByPieceStatus(ctx context.Context, mAddr address.Address, pieceStatus types.PieceStatus) ([]*types.MinerDeal, error) {
query := sdr.WithContext(ctx).Table(storageDealTableName).Where("piece_status = ?", pieceStatus)
if mAddr != address.Undef {
query.Where("cdp_provider=?", DBAddress(mAddr).String())
}

var dbDeals []*storageDeal
if err := query.Find(&dbDeals).Error; err != nil {
return nil, err
}

return fromDbDeals(dbDeals)
}

func (sdr *storageDealRepo) GetDealsByPieceStatusAndDealStatus(ctx context.Context, mAddr address.Address, pieceStatus types.PieceStatus, dealStatus ...storagemarket.StorageDealStatus) ([]*types.MinerDeal, error) {
query := sdr.WithContext(ctx).Table(storageDealTableName).Where("piece_status = ?", pieceStatus)
if len(dealStatus) > 0 {
Expand Down
23 changes: 0 additions & 23 deletions models/mysql/storage_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,28 +217,6 @@ func testGetGetDealByDealID(t *testing.T, r repo.Repo, mock sqlmock.Sqlmock) {
assert.Equal(t, deal, res)
}

func testGetDealsByPieceStatus(t *testing.T, r repo.Repo, mock sqlmock.Sqlmock) {
deal := storageDealCases[0]
dbDeal := dbStorageDealCases[0]

db, err := getMysqlDryrunDB()
assert.NoError(t, err)

rows, err := getFullRows(dbDeal)
assert.NoError(t, err)

var md []storageDeal
sql, vars, err := getSQL(db.Table((&storageDeal{}).TableName()).Where("piece_status = ?", deal.PieceStatus).Where("cdp_provider=?", DBAddress(deal.Proposal.Provider).String()).Find(&md))
assert.NoError(t, err)

mock.ExpectQuery(regexp.QuoteMeta(sql)).WithArgs(vars...).WillReturnRows(rows)

res, err := r.StorageDealRepo().GetDealsByPieceStatus(context.Background(), deal.Proposal.Provider, deal.PieceStatus)
assert.NoError(t, err)
assert.Equal(t, 1, len(res))
assert.Equal(t, deal, res[0])
}

func testGetDealsByPieceStatusAndDealStatus(t *testing.T, r repo.Repo, mock sqlmock.Sqlmock) {
deal := storageDealCases[0]
dbDeal := dbStorageDealCases[0]
Expand Down Expand Up @@ -469,7 +447,6 @@ func TestStorageDealRepo(t *testing.T) {

t.Run("mysql test GetDealByAddrAndStatus", wrapper(testGetDealByAddrAndStatus, r, mock))
t.Run("mysql test GetDealByDealID", wrapper(testGetGetDealByDealID, r, mock))
t.Run("mysql test GetDealsByPieceStatus", wrapper(testGetDealsByPieceStatus, r, mock))
t.Run("mysql test GetDealsByPieceStatus", wrapper(testGetDealsByPieceStatusAndDealStatus, r, mock))

t.Run("mysql test UpdateDealStatus", wrapper(testUpdateDealStatus, r, mock))
Expand Down
3 changes: 1 addition & 2 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ type StorageDealRepo interface {

//todo rename Getxxx to Listxxx if return deals list
GetDeals(ctx context.Context, mAddr address.Address, pageIndex, pageSize int) ([]*types.MinerDeal, error)
//GetDealsByPieceStatus list deals by providor and piece status, but if addr is Undef, only filter by piece status
GetDealsByPieceStatus(ctx context.Context, mAddr address.Address, pieceStatus types.PieceStatus) ([]*types.MinerDeal, error)
//GetDealsByPieceStatusAndDealStatus list deals by providor, piece status and deal status, but if addr is Undef, only filter by piece status
GetDealsByPieceStatusAndDealStatus(ctx context.Context, mAddr address.Address, pieceStatus types.PieceStatus, dealStatus ...storagemarket.StorageDealStatus) ([]*types.MinerDeal, error)
//GetDealsByDataCidAndDealStatus query deals from address data cid and deal status, if mAddr equal undef wont filter by address
GetDealsByDataCidAndDealStatus(ctx context.Context, mAddr address.Address, dataCid cid.Cid, pieceStatuss []types.PieceStatus) ([]*types.MinerDeal, error)
Expand Down
4 changes: 2 additions & 2 deletions models/storage_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ func testStorageDeal(t *testing.T, dealRepo repo.StorageDealRepo) {
assert.Len(t, deals, 1)
compareDeal(t, deals[0], deal2)

deals, err = dealRepo.GetDealsByPieceStatus(ctx, deal2.ClientDealProposal.Proposal.Provider, types.Proving)
deals, err = dealRepo.GetDealsByPieceStatusAndDealStatus(ctx, deal2.ClientDealProposal.Proposal.Provider, types.Proving)
assert.Nil(t, err)
assert.Len(t, deals, 1)
compareDeal(t, deals[0], deal2)

deals, err = dealRepo.GetDealsByPieceStatus(ctx, address.Undef, types.Proving)
deals, err = dealRepo.GetDealsByPieceStatusAndDealStatus(ctx, address.Undef, types.Proving)
assert.Nil(t, err)
assert.Len(t, deals, 2)

Expand Down
3 changes: 2 additions & 1 deletion storageprovider/deal_assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (ps *dealAssigner) GetUnPackedDeals(ctx context.Context, miner address.Addr
spec.MaxPiece = defaultMaxPiece
}

mds, err := ps.repo.StorageDealRepo().GetDealsByPieceStatus(ctx, miner, types.Undefine)
mds, err := ps.repo.StorageDealRepo().GetDealsByPieceStatusAndDealStatus(ctx, miner, types.Undefine, storagemarket.StorageDealAwaitingPreCommit)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -206,6 +206,7 @@ func (ps *dealAssigner) AssignUnPackedDeals(ctx context.Context, sid abi.SectorI
var deals []*types.DealInfoIncludePath

for _, md := range mds {

// 订单筛选和组合的逻辑完全由 pickAndAlign 完成
deals = append(deals, &types.DealInfoIncludePath{
DealProposal: md.Proposal,
Expand Down

0 comments on commit d2115b7

Please sign in to comment.