samedi 22 août 2015

Parse.com - Get objects randomly from table with no repititions

I have a table with a lot of info there. Currently there are 100 hundred rows but will be extended to at least 1000 (10k later, etc).

I'm trying to figure out how can I send random items to my client with the following conditions:

  • I would like to send items in chunks (like 10 at the time)

  • I don't want my items to repeat until user will see all of them (then he will see already seen records)

I have several ideas for implementing this but all of them seems ugly to me so I wish you can help me to choose or maybe even offer a best practice for that type of problem.

Here are my guesses with increasing ugliness:

  1. Pre-create scenarios (scenario = array of indexes/objectIds), create like 7-8 random arrays which will define incoming order of the records. Problems: Is it okay to store 1000 items array in the field on parse table? Will it be fast to retrieve these array and copy a chunk from given index every time?
  2. Generate unique scenario for each client. Problems: Can't use chunks, will need to retrieve objects one by one. Can't update database live, becuase scenario won't be regenerated until I update the app on AppStore and Play Market.
  3. Remember which records user had seen and search for a random until unseen is found. Problems: very ugly and obviously will be slow.



Aucun commentaire:

Enregistrer un commentaire