stravid/slotcars — pull request #154 by stravid (2012-05-02 15:38:28+00:00)
Title: Pull Request: chore/user-highscores

I programmed this because it will enable us to do more cool things. Although it didn't was of high priority. Sorry :-(

What does it do?

Whenever a new user model is created on the client side it will automatically load all highscores for this user. A user highscore is actually the best run of the user on a track. So the user highscores look like this:
```
[
{
track_id: 1,
time: 16112,
rank: 2
},
{
track_id: 18,
time: 5754,
rank: 1
}
]
```

**I'm very unhappy with the current implementation!**

If you look in the `User.rb` model you will see what I mean. This is ugly as shit and I'm pretty sure it is also really really not performant. The hard thing is you have to do a few things to get the user highscores:

1. Find all tracks where the user has atleast one stored run.
2. Build the track highscores for each track.
3. Find the users entry and rank.

I don't know if somebody manages to come up with a better solution, but I think we should try to find a better solution in the future.