Skip to content

Commit 19ba55d

Browse files
authored
Merge pull request #1534 from 0chain/feat/optimize-getref
Calculate hash in get file refs
2 parents 5fbfbf2 + 712a633 commit 19ba55d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

zboxcore/sdk/filerefsworker.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type ObjectTreeRequest struct {
5151
type oTreeResponse struct {
5252
oTResult *ObjectTreeResult
5353
err error
54+
hash string
5455
}
5556

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

8682
if _, ok := hashCount[hash]; ok {
8783
hashCount[hash]++
@@ -191,6 +187,12 @@ func (o *ObjectTreeRequest) getFileRefs(oTR *oTreeResponse, bUrl string) {
191187
return
192188
}
193189
oTR.oTResult = &oResult
190+
similarFieldRefs := make([]byte, 0, 32*len(oResult.Refs))
191+
for _, ref := range oResult.Refs {
192+
decodeBytes, _ := hex.DecodeString(ref.SimilarField.FileMetaHash)
193+
similarFieldRefs = append(similarFieldRefs, decodeBytes...)
194+
}
195+
oTR.hash = zboxutil.GetRefsHash(similarFieldRefs)
194196
}
195197

196198
// Blobber response will be different from each other so we should only consider similar fields

zboxcore/zboxutil/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func NewObjectTreeRequest(baseUrl, allocationID string, allocationTx string, pat
356356
}
357357

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

0 commit comments

Comments
 (0)