// @dev An array that contains all the Cids of IPFS Content
string[] public cidsArray;
// Unique Cid to Content struct.
mapping(string => Content) public contentsMapping;
function getTotalContentCount() public view returns (uint256) {
return cidsArray.length;
}
/*
@dev
If you have a public state variable of array type,
then you can only retrieve single elements of the array via the generated getter function.
Therefore the entire array can only be returned by a function
*/
// @notice Function that returns entire cid array.
function getCidArray() public view returns (string[] memory) {
return cidsArray;
}
So is it a good idea to get the whole array at once using that getCidArray() function, or is it better to get the array length and iterate through the generated getter function for the same array?
On the frontend ofcourse (next.js)
Which way is better and why?
It looks like both works, but what if the array contains a million elements?