2

Actually my question is the same as stated here https://parse.com/questions/issue-with-using-countobjects-on-class-with-large-number-of-objects-millions which is a 9 months old thread that unfortunately never got a real answer.

I have a parse backend for a mobile game, and I want to query the global rank of the user based on his score.

How can I query this, assuming I have more than 1000 users, and a lot more score entries?

Also, I want to be able to query the all-time rank as well as the last-24-hours rank.

Is this even possible with parse?

matthias_buehlmann
  • 4,641
  • 6
  • 34
  • 76

2 Answers2

0

If you need to do large queries like that, you should redesign your solution. Keep a leaderboard class that gets updated with cloud code; either in an afterSave hook, or with a scheduled job that runs regularly. Your primary focus must be on lightning fast lookups. As soon as your lookups start getting large or calculation heavy, you should redesign your backend for scalability.

Marius Waldal
  • 9,537
  • 4
  • 30
  • 44
0

Solution for all time and time based leader boards is

You should keep records all users score in separate entity suppose LeaderBoard and maintain top users of all time leader board or time base leader board users list in separate entity suppose TopScoreUsers. In this way you do not need to run query every time on actual leader board entity(i.e LeaderBoard) to get your top users.

Suppose your app/game has all time leader board that should show 100 top users only. When any user submit score then you check first, is this user fall in top 100 users list (from TopScoreUser), if yes then add it in separate entity named TopScoreUser (if this list already has 100 users then find place of current user in this list and remove last record) and then update user's own score in LeaderBoard entity otherwise only update user score in LeaderBoard entity.

Same case is for Time based leader board.

For user rank, recommended way is to use some calculation or formula to determine approximately rank otherwise it is tough to find/manage user actual rank if users are in millions.

Hopefully this will help you.

Ali Adnan
  • 1
  • 1