交易操作的功能是超时。我无法找出问题所在。我不确定它是否与firebase存在问题。
exports.ComputeUserReviews = functions.database.ref("/reviews/{userid}/{jobid}").onWrite((event) => {
const userid = event.params.userid;
const parentRefPromise = admin.database().ref(`reviews/${userid}`).once('value');
const UserReviewRef = admin.database().ref(`users/${userid}/account`);
return Promise.all([parentRefPromise]).then(results => {
const userReviewSnapshot = results[0];
const hasreviewPromise = UserReviewRef.child("hasreview").transaction(current => {
if (userReviewSnapshot.numChildren() === 0) {
return false;
} else if (userReviewSnapshot.numChildren() > 0) {
return true;
}
});
const reviewcountPromise = UserReviewRef.child("reviewcount").transaction(current => {
if (event.data.exists() && !event.data.previous.exists()) {
return (current || 0) + 1;
} else if (!event.data.exists() && event.data.previous.exists()) {
return (current || 0) - 1;
}
});
return Promise.all([hasreviewPromise, reviewcountPromise]);
});
});
答案 0 :(得分:0)
firebase SDK存在问题,因为添加.then(()=>{console.log('message');});
的解决方法可以修复超时。
const reviewcountPromise = UserReviewRef.child("reviewcount").transaction(current => {
if (event.data.exists() && !event.data.previous.exists()) {
return (current || 0) + 1;
} else if (!event.data.exists() && event.data.previous.exists()) {
return (current || 0) - 1;
}
}).then(()=>{console.log('message');});