Note that there are some explanatory texts on larger screens.

plurals
  1. POReal time update of relative leaderboard for each user among friends
    text
    copied!<p>Ive been working on a feature of my application to implement a leaderboard - basically stack rank users according to their score. Im currently tracking the score on an individual basis. My thought is that this leaderboard should be relative instead of absolute i.e. instead of having the top 10 highest scoring users across the site, its a top 10 among a user's friend network. This seems better because everyone has a chance to be #1 in their network and there is a form of friendly competition for those that are interested in this sort of thing. Im already storing the score for each user so the challenge is how to compute the rank of that score in real time in an efficient way. Im using Google App Engine so there are some benefits and limitations (e.g., IN [array]) queries perform a sub-query for every element of the array and also are limited to 30 elements per statement</p> <p>For example</p> <p>1st Jack 100 </p> <p>2nd John 50 </p> <p>Here are the approaches I came up with but they all seem to be inefficient and I thought that this community could come up with something more elegant. My sense is that any solution will likely be done with a cron and that I will store a daily rank and list order to optimize read operations but it would be cool if there is something more lightweight and real time</p> <ol> <li>Pull the list of all users of the site ordered by score. For each user pick their friends out of that list and create new rankings. Store the rank and list order. Update daily. Cons - If I get a lot of users this will take forever</li> </ol> <p>2a. For each user pick their friends and for each friend pick score. Sort that list. Store the rank and list order. Update daily. Record the last position of each user so that the pre-existing list can be used for re-ordering for the next update in order to make it more efficient (may save sorting time)</p> <p>2b. Same as above except only compute the rank and list order for people who's profiles have been viewed in the last day Cons - rank is only up to date for the 2nd person that views the profile</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload