Forum BigDB Best way to keep track of voters?

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

Best way to keep track of voters?

Postby Vania » September 5th, 2011, 4:26 pm

I need to keep track of who has voted on which map (for maps rating) using BigDB.

Right now, in every map object, I keep a DatabaseArray with the list of unique id's of the players that have already voted.

Is this a naive solution? I was wondering if there was a better way...
Vania
 
Posts: 198
Joined: March 24th, 2010, 9:01 pm

Re: Best way to keep track of voters?

Postby nulllgames » September 5th, 2011, 8:09 pm

.
Last edited by nulllgames on August 26th, 2012, 12:56 pm, edited 1 time in total.
http://nulll-void.com/games/ - scifi themed flash games
User avatar
nulllgames
 
Posts: 10
Joined: January 25th, 2011, 9:41 pm

Re: Best way to keep track of voters?

Postby Oliver » September 6th, 2011, 7:50 pm

The correct way is to keep the current count on the object being counted, and have another table with objects indicating if a user has voted on object, like so:

(Pseudo code, you'd have to do this serverside...)

Code: Select all
public vote(DatabaseObject target){
   if( !allowVote(target.key) ){
     target.voteCount++;
     target.save();
   }
}

public bool allowVote(string uniqueIdentifier){
   if( not object exists for unique identifier ){
      create object for unique identifier()
      return true;
   }else{ return false; }
}


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

Re: Best way to keep track of voters?

Postby Vania » September 6th, 2011, 8:40 pm

Thanks a lot for asnwering Oliver!

Just let me see if I got it right:

I have to make a table that is used only for keeping track of the votes.

I have to make a unique identifier that combines the mapId and the userId, like: "[map_id]:[user_id]",
then when user X votes on map Y I add a new empty object to the table called "X:Y"

That's correct right?
Vania
 
Posts: 198
Joined: March 24th, 2010, 9:01 pm

Re: Best way to keep track of voters?

Postby Oliver » September 6th, 2011, 8:53 pm

Yep, that way the user can only vote once on each object.

You can also expand a bit* on the basic method to make it such that users can change their votes.

Best,
Oliver

*) Left as an exercise to the reader
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to BigDB