Skip to content

Commit

Permalink
Merge pull request #440 from ipfs-force-community/feat/list-deal-desc…
Browse files Browse the repository at this point in the history
…ending-by-default

feat: list deal descending by default
  • Loading branch information
LinZexiao authored Sep 22, 2023
2 parents 26dddf5 + 1e656f1 commit 03f8555
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cli/storage-deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ part states:
Name: "watch",
Usage: "watch deal updates in real-time, rather than a one time list",
},
&cli.BoolFlag{
Name: "oldest",
Usage: "sort by oldest first",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := NewMarketNode(cctx)
Expand Down Expand Up @@ -398,6 +402,9 @@ part states:
Limit: cctx.Int(limitFlag.Name),
},
}
if cctx.Bool("oldest") {
params.Asc = true
}

ctx := ReqContext(cctx)
deals, err := api.MarketListIncompleteDeals(ctx, &params)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/specs-actors/v2 v2.3.6
github.com/filecoin-project/specs-actors/v7 v7.0.1
github.com/filecoin-project/venus v1.13.1-0.20230918055732-dd01c6722800
github.com/filecoin-project/venus v1.13.1-0.20230922072850-5a527ea220b8
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,8 @@ github.com/filecoin-project/specs-storage v0.4.1 h1:yvLEaLZj8f+uByhNC4mFOtCUyL2w
github.com/filecoin-project/specs-storage v0.4.1/go.mod h1:Z2eK6uMwAOSLjek6+sy0jNV2DSsMEENziMUz0GHRFBw=
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/venus v1.11.1/go.mod h1:H8A3djsrHKRWuKnJI/8Y6xZRudbV9V2x5NIP8/PVPfQ=
github.com/filecoin-project/venus v1.13.1-0.20230918055732-dd01c6722800 h1:fHJQPqCNUrGYODltBjOvzU5rIRy7y5SAh2NFh/2qibA=
github.com/filecoin-project/venus v1.13.1-0.20230918055732-dd01c6722800/go.mod h1:RtrF8fCy1xrCytfaVMvPU2J3JrcMqapzvJpvK5CKdTA=
github.com/filecoin-project/venus v1.13.1-0.20230922072850-5a527ea220b8 h1:Wj4hMLDQb5B+ibssYQpOZ3KFoA6hK2UdaG+4pE5zB/E=
github.com/filecoin-project/venus v1.13.1-0.20230922072850-5a527ea220b8/go.mod h1:RtrF8fCy1xrCytfaVMvPU2J3JrcMqapzvJpvK5CKdTA=
github.com/filecoin-project/venus-auth v1.11.0/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
Expand Down
6 changes: 6 additions & 0 deletions models/badger/storage_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package badger
import (
"bytes"
"context"
"sort"

"github.com/filecoin-project/go-address"
cborrpc "github.com/filecoin-project/go-cbor-util"
Expand Down Expand Up @@ -270,6 +271,11 @@ func (sdr *storageDealRepo) ListDeal(ctx context.Context, params *types.StorageD
return nil, err
}

// sort by time
sort.Slice(storageDeals, func(i, j int) bool {
return (storageDeals[i].TimeStamp.CreatedAt < storageDeals[j].TimeStamp.CreatedAt) == params.Asc
})

return storageDeals, nil
}

Expand Down
5 changes: 5 additions & 0 deletions models/mysql/storage_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ func (sdr *storageDealRepo) ListDeal(ctx context.Context, params *types.StorageD
state != storagemarket.StorageDealExpired && state != storagemarket.StorageDealError
}
query := sdr.Table(storageDealTableName).Offset(params.Offset).Limit(params.Limit)
if params.Asc {
query.Order("created_at asc")
} else {
query.Order("created_at desc")
}
if !params.Miner.Empty() {
query.Where("cdp_provider = ?", DBAddress(params.Miner).String())
}
Expand Down
2 changes: 1 addition & 1 deletion models/mysql/storage_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func TestListDeal(t *testing.T) {
caseCount := len(storageDealCases)
defPage := types.Page{Limit: caseCount}
newQuery := func() *gorm.DB {
return db.Table((&storageDeal{}).TableName())
return db.Table((&storageDeal{}).TableName()).Order("created_at desc")
}

// empty params
Expand Down

0 comments on commit 03f8555

Please sign in to comment.