Skip to content

Commit

Permalink
Merge pull request #507 from ipfs/fix/fast-repo-stat
Browse files Browse the repository at this point in the history
IPFSHttp: Add "size-only=true" flag to repo/stat calls
  • Loading branch information
hsanjuan committed Aug 20, 2018
2 parents 2f59eaf + 5a0d4ed commit 8d3510e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions ipfsconn/ipfshttp/ipfshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ type ipfsIDResp struct {
type ipfsRepoStatResp struct {
RepoSize uint64
StorageMax uint64
NumObjects uint64
}

type ipfsAddResp struct {
Expand Down Expand Up @@ -924,7 +923,7 @@ func getConfigValue(path []string, cfg map[string]interface{}) (interface{}, err
func (ipfs *Connector) FreeSpace() (uint64, error) {
ctx, cancel := context.WithTimeout(ipfs.ctx, ipfs.config.IPFSRequestTimeout)
defer cancel()
res, err := ipfs.postCtx(ctx, "repo/stat", "", nil)
res, err := ipfs.postCtx(ctx, "repo/stat?size-only=true", "", nil)
if err != nil {
logger.Error(err)
return 0, err
Expand All @@ -944,7 +943,7 @@ func (ipfs *Connector) FreeSpace() (uint64, error) {
func (ipfs *Connector) RepoSize() (uint64, error) {
ctx, cancel := context.WithTimeout(ipfs.ctx, ipfs.config.IPFSRequestTimeout)
defer cancel()
res, err := ipfs.postCtx(ctx, "repo/stat", "", nil)
res, err := ipfs.postCtx(ctx, "repo/stat?size-only=true", "", nil)
if err != nil {
logger.Error(err)
return 0, err
Expand Down
7 changes: 6 additions & 1 deletion test/ipfs_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,15 @@ func (m *IpfsMock) handler(w http.ResponseWriter, r *http.Request) {
}
w.Write(data)
case "repo/stat":
sizeOnly := r.URL.Query().Get("size-only")
len := len(m.pinMap.List())
numObjs := uint64(len)
if sizeOnly == "true" {
numObjs = 0
}
resp := mockRepoStatResp{
RepoSize: uint64(len) * 1000,
NumObjects: uint64(len),
NumObjects: numObjs,
StorageMax: 10000000000, //10 GB
}
j, _ := json.Marshal(resp)
Expand Down

0 comments on commit 8d3510e

Please sign in to comment.