Parse.Cloud.define("bulkUpdateUserViewedTraces", function(request, response){
Parse.Cloud.useMasterKey();
var userQuery = new Parse.Query(Parse.User);
userQuery.limit(200);
var userCount = 0;
userQuery
.find(function (users) {
var promises = _.map(users, function (user){
userCount++;
return populateViewedTraces(user);
});
return promises;
})
.then(function (promises) {
return Parse.Promise.when(promises);
})
.then(function(){
console.log("Processed " + userCount + " users");
response.success("Processed " + userCount + " users");
}, function(error){
console.error(JSON.stringify(error));
response.error(error);
});
});
function populateViewedTraces (user) {
var viewedTracesCount = 0;
var viewHistoryQuery = new Parse.Query("ViewHistory");
viewHistoryQuery.equalTo("user", user);
return viewHistoryQuery
.each(function (viewHistory) {
console.log("Got here");
viewedTracesCount++;
})
.then(function () {
console.log("Got here 2");
return user.save();
});
}
不起作用。记录“已处理x用户”但从不记录“到达此处”。承诺应该在when()调用期间执行,但永远不会执行。
这绝对没有任何意义,因为我所看到的每篇文章都是这样写的。出于某种原因,这并没有做任何事情。