Forum BigDB Efficiently Loading an Arbitrary Range

Discussion and help relating to the PlayerIO database solution, BigDB.

Efficiently Loading an Arbitrary Range

Postby truefire » December 16th, 2010, 6:42 pm

I have a system for displaying top scores. Each page shows 10 entries, so the first page shows 1-10, second shows 11-20, etc. Up until now, I've just been loading the entire DB, saving it to an array, and then just displaying the respective elements in that array for each page. But I've realized that, as this DB will potentially have thousands of entries, this can be very inefficient, since the entire DB will be reloaded every time the player refreshes the list. I know I can use the limit parameter to limit the number of entries, but the problem is getting the start entry. Say, for example, the player wants to skip from page 1 to page 30. In order to load the entries for page 30 with loadRange, I need to either load the entire DB (which is out of the question), or know the score of the first object. And in order to find that, I'd need to load the entire DB up until that point. So, I'm looking for a way to load only a specific range of elements, by an index, based not on the values of some variable in the DBObject, but based on the position which it appears in when sorted by the index.

Thanks in advance.
truefire
 
Posts: 15
Joined: November 22nd, 2010, 6:01 am

Re: Efficiently Loading an Arbitrary Range

Postby Oliver » December 17th, 2010, 12:22 pm

based not on the values of some variable in the DBObject, but based on the position which it appears in when sorted by the index.


What you're describing is a ranking index, that enables you to ask queries such as "what position am i at" and "who is at positions 1384 to 1394", right? We don't support them directly, because we can't figure out a good way to implement them in a truly scalable fashion.

An easy workaround in your case though, since you're already starting all queries at the top, is simply to use the loadRange method and calculate the ranking positions yourself (starting at #1). Then when the user clicks the next page link, you can load the next page of results and start the ranking at previous-max-position.

Hope that helps,
- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Efficiently Loading an Arbitrary Range

Postby truefire » December 17th, 2010, 3:09 pm

I see what you're saying. But my system is set up so that the player will not necessarily have to pass through every page. For example, the player could skip directly from page 1 to page 350. Obviously, I'd like to not load the data on pages 2-349, because the player won't even see those pages. Additionally. if the player is on page 350, and presses refresh, I'll have to recalculate all the other pages just to refresh the player's current page. Is there no way that I can do this?
truefire
 
Posts: 15
Joined: November 22nd, 2010, 6:01 am

Re: Efficiently Loading an Arbitrary Range

Postby Oliver » December 17th, 2010, 3:12 pm

Is there no way that I can do this?


We used a setup in another game where the developer setup a schedule program (using the c# api) to loop over all entries (using an index and loadrange) and update a .ranking property.

This seems bad, but actually not that bad since most users won't change positions that often and .save() on a bigdb object will only actually save the changes if there are any changes.

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Efficiently Loading an Arbitrary Range

Postby truefire » December 17th, 2010, 6:54 pm

I might have to use a setup like that one, though it's not ideal for my game. The scores are an important part of gameplay, so they'd need to be updated in pseudo-realtime (currently, I have the server updating the DB every 15 seconds), and with a lot of entries, that can add up... Do server-BigDB interractions count towards the game traffic?
truefire
 
Posts: 15
Joined: November 22nd, 2010, 6:01 am


Return to BigDB