i am designing a pyramid scheme for my customer, he going to apply this structure to the system. It is a referal scheme, if intro someone to join the website, all upper layer will enjoy the referal fee.
This is my table structure, so based on the referral by column, i can find back all the upper line or lower line of the particular user.
However when i using this statement to loop, (sorry cannot provide full code since it is big, but it can be easily to understand with the below code)
for (int a = 0; a < lowerLine.Count; a++)
{
var query3 = from data in db.users_table where data.referral_by == referralUser && data.is_activated == true select new{ data.user_id,data.introducer};
var lowerLine2 = query3.ToList();
lowerLineCount2 += lowerLine2.Count;
totalCount += lowerLine2.Count;
}
It is a linq statement and it will keep looping until end of the pyramid to get total referral. However if execute this thing, if he have 500 referal, it will become very slow to get all the data.
In this case, i think a solution to get all data through stored procedure, however when i tried to execute that statement for 500 times, the performance still 26 seconds which is still very slow, my requirement is maximum 10 seconds to get all the data out. As a result, the stored procedure is not a choice since it will still slow when execute at once
May i know how to get all the data out with this pyramid scheme within 10 seconds? I dont mind to indexing, however i did the indexing on the referral by the result is still slow