Skip to content

Commit

Permalink
Improve NFT metadata caching
Browse files Browse the repository at this point in the history
  • Loading branch information
h0ngcha0 committed Aug 15, 2024
1 parent 4e7aefa commit 8069285
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,15 @@ async function getNftMetadataz(nftIds: string[], explorerProvider: ExplorerProvi
}
}

let newNftMetadataz: NFTMetadata[] = []
const newNftMetadataz: NFTMetadata[] = []
if (nftIdsWithoutMetadata.length !== 0) {
newNftMetadataz = (await Promise.all(
chunk(nftIdsWithoutMetadata, maxSizeTokens).map((ids) =>
explorerProvider.tokens.postTokensNftMetadata(ids)
)
)).flat()
}

for (const newNftMetadata of newNftMetadataz) {
await storeImmutable(`${newNftMetadata.id}-nft-metadata`, newNftMetadata)
for (const ids of chunk(nftIdsWithoutMetadata, maxSizeTokens)) {
const newMetadataz = await explorerProvider.tokens.postTokensNftMetadata(ids)
newNftMetadataz.push(...newMetadataz)
for (const newMetadata of newMetadataz) {
await storeImmutable(`${newMetadata.id}-nft-metadata`, newMetadata)
}
}
}

return cachedNftMetadataz.concat(newNftMetadataz)
Expand Down

0 comments on commit 8069285

Please sign in to comment.