Skip to content

Commit

Permalink
Merge pull request #1534 from 0chain/feat/optimize-getref
Browse files Browse the repository at this point in the history
Calculate hash in get file refs
  • Loading branch information
dabasov committed Jun 17, 2024
2 parents 5fbfbf2 + 712a633 commit 19ba55d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions zboxcore/sdk/filerefsworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ObjectTreeRequest struct {
type oTreeResponse struct {
oTResult *ObjectTreeResult
err error
hash string
}

// Paginated tree should not be collected as this will stall the client
Expand All @@ -76,12 +77,7 @@ func (o *ObjectTreeRequest) GetRefs() (*ObjectTreeResult, error) {
}
continue
}
var similarFieldRefs []byte
for _, ref := range oTreeResponse.oTResult.Refs {
decodeBytes, _ := hex.DecodeString(ref.SimilarField.FileMetaHash)
similarFieldRefs = append(similarFieldRefs, decodeBytes...)
}
hash := zboxutil.GetRefsHash(similarFieldRefs)
hash := oTreeResponse.hash

if _, ok := hashCount[hash]; ok {
hashCount[hash]++
Expand Down Expand Up @@ -191,6 +187,12 @@ func (o *ObjectTreeRequest) getFileRefs(oTR *oTreeResponse, bUrl string) {
return
}
oTR.oTResult = &oResult
similarFieldRefs := make([]byte, 0, 32*len(oResult.Refs))
for _, ref := range oResult.Refs {
decodeBytes, _ := hex.DecodeString(ref.SimilarField.FileMetaHash)
similarFieldRefs = append(similarFieldRefs, decodeBytes...)
}
oTR.hash = zboxutil.GetRefsHash(similarFieldRefs)
}

// Blobber response will be different from each other so we should only consider similar fields
Expand Down
2 changes: 1 addition & 1 deletion zboxcore/zboxutil/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func NewObjectTreeRequest(baseUrl, allocationID string, allocationTx string, pat
}

func NewRefsRequest(baseUrl, allocationID, allocationTx, path, pathHash, authToken, offsetPath, updatedDate, offsetDate, fileType, refType string, level, pageLimit int) (*http.Request, error) {
nUrl, err := joinUrl(baseUrl, REFS_ENDPOINT, allocationID)
nUrl, err := joinUrl(baseUrl, REFS_ENDPOINT, allocationTx)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 19ba55d

Please sign in to comment.