为什么我仅添加新文档时,Firebase Firestore计数会读取操作? [英] Why Firebase Firestore count reads operations while I am just adding new documents only?
问题描述
我已经创建了一个带有Firebase Functions usign node.js的API端点.这 API端点从客户端浏览器收集JSON数据,我正在使用Firebase函数将该JSON数据保存到Firebase Firestore数据库.
I have created and an API endpoint with Firebase Functions usign node.js. This API endpoint collect JSON data from client browser and I am saving that JSON data to Firebase Firestore databse using Firebase Functions.
虽然这很好用,但是当我看到Firestore使用选项卡时,它显示的读取操作的数量确实很高,即使到目前为止我还没有创建任何读取功能.
While this works fine but when I see Firestore usage tab it's shows really high number of read operations even I have not created any read function till now.
我的API正在生产中,当前使用情况数据为:读取9.7K,写入1K,删除0.
My API is in Production and and current usage data is : Reads 9.7K, Writes 1K, Deletes 0.
我已经尝试检查Firebase Firestore文档和定价,但似乎从未在此问题上找到任何东西.
I have already tried to check with Firebase Firestore Document and Pricing but never seems to find anything on this issue.
我正在使用Firestore添加功能来创建具有自动生成的文档ID的文档. ValidateSubscriberData()是一个简单的函数,用于验证客户端要求的主体输入(即JSON数据).
I am using Firestore add function to create document with an auto generated document id. ValidateSubscriberData() is a simple function to validate client req.body inputs which is JSON data.
app.post('/subscribe', (req, res) => {
let subscriber = {};
ValidateSubscriberData(req.body)
.then(data => {
subscriber = data;
//console.log(data);
subscriber.time = Date.now();
return subscriber;
})
.then(subscriber => {
//console.log(subscriber);
// noinspection JSCheckFunctionSignatures
return db.collection(subscriber.host).add(subscriber);
})
.then(document => {
console.log(document.id);
res.json({id: document.id, iid: subscriber.iid});
return 0;
})
.catch(error => {
console.log({SelfError: error});
res.json(error);
});
});
我不知道这是Firestore的问题,或者我正在以某种方式在内部进行读取操作,但是我想找到一种方式来优化我的代码.
I don't know this is an issue with Firestore or I am doing something in a way that makes read operations internally but I want find a way so I can optimize my code.
英语不是我的母语,我正在尽我最大的努力来解释我的问题.
English is not my first language and I am trying my best explain my issue.
推荐答案
我认为Firestore可以正常工作,我的代码也可以.我认为Firebase正在计算我通过Firebase控制台进行的读取.
I think Firestore is working perfectly fine and my code too. I assume Firebase is counting those reads which I made through Firebase Console.
要验证这一点,我单击了Firestore页面上的Data选项卡,然后向下滚动以显示所有文档名称/id.在那之后,我看到我的旧数据增加了1000读.因此,它经过验证的Firestore甚至可以计数从Firebase控制台读取的所有内容,这很明显,但是我不好,我以前没有考虑过这一点.
To verify this I have clicked on Data tab on Firestore page and scroll down to make all document name/id visible. And after that I see 1K Reads added on my old stats. So its proven Firestore counting all reads even its from firebase console and it is obvious but my bad I have not thinking about this before.
我认为这个问题没有任何意义,但是也许像我这样的人在将这个愚蠢的问题发布到这个有用的平台之前发现它有帮助.
I don't think this question has any relevance but may be people like me find it helpful before posting any silly question on this helpful platform.
这篇关于为什么我仅添加新文档时,Firebase Firestore计数会读取操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!