I am currently building a project where the users can referr other persons. Now let's say I have a user who has only 2 referrals but those 2 also have another 2, then again 2 etc. and that for much more. Now I want to output those referrals/users and their users. To get a users referrals, the function getUser(uint _userId) is called. It returns some values and an array _referrals that contains the IDs of the users that specific user has referred. Now it's required to again call getUser for the 2 users until at one point it returns that a user has no referrals.
I currently am doing this via
struct User {
mapping(uint => uint) directReferrals; // Referrals
mapping(uint => uint) index; // ReferralId => ID in above
uint directReferralsAmount;
}
User[] users;
function getUser(uint _userId) [...] public view returns(uint[] directReferrals) { [...] }
The problem is, that when for example a user has 100 levels of referrals (referrals of him, referrals of the referrals of him, etc.), it will call getUser (view only) 100 times (in the web interface through javascript and an ethereum node connection / MetaMask) which can result in a long waiting time.
Are there alternative ways of storing and getting of referrals? Or wouldn't 100 view-calls take that long?
What would be the best way to
1) Programm this in the solidity code and
2) Output this via javascript?
3) Is it possible to show those data in one page without a too long waiting time?
referr
,lines "down"
,againt
,downline
??? I suggest that you minimize your question to the technical part only (i.e., your project description is "obfuscated", but there's no point in fixing it to begin with, just stick to the actual technical issue).directReferrals
both as a state variable and an input argument is probably not advisable.[...]
in the middle of the function declaration doesn't make any sense.