2

我的 DNS 解析有问题,它超出配额的速度比调用我的函数的速度快。

我正在使用 firebase 云功能来监控我们用户的“已连接”状态。我们在移动应用程序的每个“onDisconnect”事件上更新一个 Firebase 数据库字段“isLive”。我实现了一个 Firebase Cloud Function 来监听这个字段。在每次调用中,我都会执行从 Firebase 数据库获取数据并更新其他数据的请求,也包括从我们的 Firebase 数据库中获取的数据。

这是我的实现,

exports.profileIsLive = functions.database.ref("users/{uid}/profile/isLive").onWrite((event) => {

   const rootRef = event.data.ref.root;

   const uuid = event.params.uid;

   const conversationRef = rootRef.child("/users/" + uuid + "/conversations");

   return conversationRef.once('value')
       .then(snapshot => {
           const updates = [];

           snapshot.forEach(function (child) {
               let conversationId = child.val();
               let otherUserUuid = child.key;

               let snippetIsLive = "users/" + otherUserUuid + "/conversations/" + conversationId + "/isLive";
               updates.push(rootRef.child(snippetIsLive).set(event.data.val()).catch(error => {
                   return;
               }));

               let participantIsLive = "conversations/" + conversationId + "/participants/" + uuid + "/isLive";
               updates.push(rootRef.child(participantIsLive).set(event.data.val()).catch(error => {
                   return;
               }));

               if (!event.data.val()) {
                   let participantLastSeen = "conversations/" + conversationId + "/participants/" + uuid + "/lastSeen";
                   updates.push(rootRef.child(participantLastSeen).set(admin.database.ServerValue.TIMESTAMP).catch(error => {
                       return;
                   }));
               }
           });

           return Promise.all(updates);
       });
});

我不明白为什么我在这里有 DNS 解析。每次调用 Firebase 数据库都有解决方案吗?如果是这样,为什么 DNS 解析配额设置为 4000,我们每天可以有数百万次调用?

非常感谢您的任何建议。

4

0 回答 0