To prevent certain objects from being created, I incorporated a conditional in the beforeSave cloud function of that object type.
However, when two objects are created at the same time, the conditional fails to work as expected.
Check out my code snippet below:
Parse.Cloud.beforeSave("Entry", function(request, response) {
var theContest = request.object.get("contest");
theContest.fetch().then(function(contest){
if (contest.get("isFilled") == true) {
response.error('This contest is full.');
} else {
response.success();
});
});
The goal is to prevent an Entry object creation if a Contest is already at maximum capacity. However, in situations where there is only 1 spot left in the Contest and two entries are saved simultaneously, both end up getting added.
I understand this scenario may be rare, but it's still a valid concern.