Storing A Scoreboard

43 views
Skip to first unread message

monsters

unread,
May 16, 2012, 4:21:23 PM5/16/12
to rav...@googlegroups.com
So this is something I've struggled with using RDMS.. My thought with raven

store the score objects simply
{score,user,gameId}

Store a reference array in blocks of 100, store a separate user,index object to lookup individual users...

Not fully baked yet, should I just store it directly? what if I store 1,000,000 of the score objects, and ask for them back sorted, or for the first 10, or the middle 50, or the entry for a particular user... will magic raven index's make this work allright?

monsters

unread,
May 16, 2012, 5:00:06 PM5/16/12
to rav...@googlegroups.com
Just did some tests, and with 10,000 users, I'm seeing access times of < 3 ms to get an arbitrary user .. that's pretty great...

So, suggestions as to how I would find the index of a particular user, so I can get the surrounding users? linq and index are unfriendly it seems... projection with an index?

monsters

unread,
May 16, 2012, 5:51:58 PM5/16/12
to rav...@googlegroups.com
So Right now not sure how to go about this without multiple queries.. I guess the raven 'batch query' might work here..

using (var session = _documentStore.OpenSession())

            {

               

                var result =

                    session.Query<Entry>().Where(

                        x => x.User.Id == userId && x.Deck == deckId).OrderBy(x => x.Score).Customize(

                            x => x.WaitForNonStaleResultsAsOfNow()).FirstOrDefault();


                if (result != null)

                {

                    var first = session.Query<Entry>().Where(

                        x =>  x.Deck == deckId && x.Score < result.Score).OrderByDescending(

                            x => x.Score).Take(count/2);


                    var last = session.Query<Entry>().Where(

                        x =>  x.Deck == deckId && x.Score > result.Score).OrderByDescending(

                            x => x.Score).Take(count / 2);

                    results.AddRange(last);

                    results.Add(result);

                    results.AddRange(first);

                }

                return results.ToArray();

Oren Eini (Ayende Rahien)

unread,
May 16, 2012, 8:02:17 PM5/16/12
to rav...@googlegroups.com
I am not sure what you are trying to _do_ here?
why do you have three queries like that?

Ryan Heath

unread,
May 17, 2012, 9:45:14 AM5/17/12
to rav...@googlegroups.com
It seems he wants a ranking score ...
First look up an particular user then select a few scores above and
below the user rank.

I believe we had something similar on this list before ...

// Ryan

Matt Warren

unread,
May 17, 2012, 9:52:17 AM5/17/12
to rav...@googlegroups.com
Ryan,

Do you mean this thread https://groups.google.com/d/msg/ravendb/X-xEw9Ea77Q/gzuHml6I-0wJ, with the 2 solutions that you and I came up with?

monsters

unread,
May 17, 2012, 12:01:25 PM5/17/12
to rav...@googlegroups.com
That's interesting, and yes you're correct I want a scoreboard.

So the bowling solution is nice, but doesn't include a playerRank type property (ie: playerRank = 123)..

The query I have is to accomplish this, so i load the player I want, then but using < and > on scores in the subsequent queries I can get the next X and previous X scores/players.

I haven't checked, but I hope that using stats on the 'previous x' query (higher scores) will allow me to get the  actual position of the user in question

Ryan Heath

unread,
May 17, 2012, 2:00:26 PM5/17/12
to rav...@googlegroups.com
No, I think it was this one, but I don't think we ever resolved the problem:
https://groups.google.com/group/ravendb/browse_thread/thread/c2c325d2deed3ec5?hl=en&noredirect=true

// Ryan

Ryan Heath

unread,
May 17, 2012, 2:04:55 PM5/17/12
to rav...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages