I come from a HTML/PHP/MYSQL background so bear with me on this. I am in the process of developing a contract and it is going pretty well. The main issue I have at the moment is how to filter an Array created with solidity.
At the minute the Array contains a list of Structs (these are items that can be purchased). I want to be able to filter them so that i have a list of unsold items.
Now in MYSQL you can obviously query but not here. At the minute I am doing the following:
- Frontend - Call function that returns the length of the array.
- Frontend - Taking the length loop through and fetch all the items.
- Frontend - Check to see if the item is bought, if so separate into a "unsold" frontend array.
- Display items in the unsold array.
The obvious issue here is that lets say we have 1000 items, the frontend has to loop through each one and then call the function to get the items details so we end up with 2000 calls plus the filtering on top into a separate array. This obviously takes time.
I could go down the route of taking all the items from the contract and then storing them in a MYSQL db for queries but I was looking to avoid the use of DBs if possible.
Im wondering if there is a better approach to this that I don't know about? For example should I be worrying about network performance like you would do when you are fetching from lets say a single server?
Edit One way it could be made slightly easier is if I could return the Array containing the Structs in one go instead of having to do separate calls for each one based on the length.