具有交易操作的firebase的云功能已完成状态:'超时'

时间:2017-04-26 22:17:28

标签: firebase firebase-realtime-database google-cloud-functions

交易操作的功能是超时。我无法找出问题所在。我不确定它是否与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]);
  });
});

1 个答案:

答案 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');});