fix: GetMetadataByCID has bad logic

This commit is contained in:
Derrick Hammer 2024-01-09 11:01:57 -05:00
parent 71192c4169
commit 26e0a4c9df
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 25 additions and 23 deletions

View File

@ -247,15 +247,18 @@ func (n *NodeImpl) DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error)
} }
} }
func (n *NodeImpl) GetMetadataByCID(cid *encoding.CID) (metadata.Metadata, error) { func (n *NodeImpl) GetMetadataByCID(cid *encoding.CID) (md metadata.Metadata, err error) {
var md metadata.Metadata
hashStr, err := cid.Hash.ToString() hashStr, err := cid.Hash.ToString()
if err != nil { if err != nil {
return nil, err return nil, err
} }
if n.metadataCache.Contains(hashStr) { if n.metadataCache.Contains(hashStr) {
md, _ := n.metadataCache.Get(hashStr)
return md.(metadata.Metadata), nil
}
bytes, err := n.DownloadBytesByHash(&cid.Hash) bytes, err := n.DownloadBytesByHash(&cid.Hash)
if err != nil { if err != nil {
return nil, err return nil, err
@ -281,7 +284,6 @@ func (n *NodeImpl) GetMetadataByCID(cid *encoding.CID) (metadata.Metadata, error
} }
n.metadataCache.Put(hashStr, md) n.metadataCache.Put(hashStr, md)
}
return md, nil return md, nil
} }