1
votes

I'm trying to understand how to use cloud code and background job efficiently for my iOS app.

First question about Parse cloud code : - SOLVED -

I need to fetch all my User and check if the nickname is already taken when a new user sign up. (column nickname is a custom column in User table). So this can be a big request and a cloud code function would be necessary I think ??

Second question about Parse background job :

I need to fetch all objects from a Table and check for every object 1 column : dateEnd.
If dateEnd < date of Today then I put the column Enable to False. How can I do that ? and can the function run 24/24 7/7 ?

enter image description here

I'm coding only in swift, I guess I will have to take a look at javascript.
Thanks

2
The nickname query is quite simple - just whereKey nickname=Desired name. You don't need cloud code for that. You can use a cloud code background job to disable users. You can't run it 24/7 but you can schedule it to run pretty frequently; I wouldn't imagine it would take long to run. Yes, it will need to be in JavaScript - Paulw11
Ok but if I have 100.000 users I will need cloud code to fetch all this big data ? - user3722523
The nickname search will happen on the Parse cloud and it will return 0 or 1 objects. It doesn't retrieve all data and filter it in the local device; that would be insane. - Paulw11
ok thx so cloud code is useful only when u need to retrieve many values in local ? - user3722523

2 Answers

1
votes

First question

If your nickname must be unique, why not use the nickname as your username? This way, Parse does this check for you with no effort by you.

If for some reason this is not possible, then simply do a query from your client with a nickname constraint:

query.whereKey("nickname", equalTo: chosenNickname)

If this does not return any results, then nickname is not taken.

Second question

Why do you need to have this job going all the time? Is it important that the Enable column is set to false within seconds or minutes of the expiry? Could expiry be set to happen on the hour? Or at a specific time each day? If this was i.e. like handling at 30 day trial, the trial doesn't need to end at an arbitrary timestamp for every user. It could end at midnight 30 days after trial start. Consider whether your expiry can be more lenient.

0
votes

I used to do only get/refresh/save object on iOS side, everything else (I think) should be done on cloud code. Never had troubles with background jobs with such approach.