flow-nft icon indicating copy to clipboard operation
flow-nft copied to clipboard

Impossible to count number of NFTs in large collections and get the IDs

Open cybercent opened this issue 2 years ago • 7 comments

Issue to be solved

getIDs().length breaks when used on accounts with large NFT collections like 0x329feb3ab062d289.661249

failed to retrieve slab 0x329feb3ab062d289.661249: get value failed: [Error Code: 1110] computation exceeds limit (100000)

Suggested Solution

  • Add way to get the count of total NFTs by avoiding getIDs().length
  • Add way to get a slice of the IDs in the collection.

@joshuahannan I'm tagging you here as this might be interesting for the V2 standard.

cybercent avatar Aug 25 '23 11:08 cybercent

yeah I would love if we could find a solution for this that we could use with the standard

joshuahannan avatar Aug 25 '23 14:08 joshuahannan

These improvements are all related to the NFT standard, moving

turbolent avatar Aug 25 '23 18:08 turbolent

Can this be done with what we have currently? I'd guess we might have to tackle it with the V2 standards coming out with stable cadence. The main issue as I understand it is that getIDs has to load all IDs into memory which is just too costly for large collections

austinkline avatar Aug 25 '23 18:08 austinkline

To allow users to query the size of the collection, Collection should provide a getter function for it, so that users do not need to rely on the inefficient getIDs().length.

This is simple by adding:

fun getCount(): Int
    return ownedNFTs.length
}

turbolent avatar Aug 25 '23 18:08 turbolent

Looks good for getting ID count, any idea on getting a slice of the IDs without loading all of them with getIDs ?

Maybe a function to return:

ownedNFTs.slice(from: upTo:) , loop through them get the IDs and return them

cybercent avatar Aug 25 '23 19:08 cybercent

Yeah, I think getting a slice like that will require an update to Cadence

I added getLength to the new standard btw

joshuahannan avatar Aug 28 '23 18:08 joshuahannan

You could do iteration over the map and fetch the first x ones?

bjartek avatar Sep 06 '23 20:09 bjartek

getLength addresses this so I am closing

joshuahannan avatar May 07 '24 16:05 joshuahannan