【发布时间】:2021-09-12 20:00:09
【问题描述】:
我正在开发一个从 firestore 读取数据的 chrome 扩展程序,在过去的几天里,我会以最多 50 次读取完成一天的工作,今天由于某种原因它显示了高达 34K 的读取量,我该怎么做修复这个错误?
这是我的代码
useEffect(() => {
const getNotes = () => {
db.collection("Users")
.doc(user.email)
.collection("Notes")
.get()
.then((snapshot) => {
const loadedNotes = snapshot.docs.map((docs) => {
return {
note: docs.data().note,
id: docs.id,
};
});
setNotes(Object.values(loadedNotes) ?? []);
});
};
getNotes();
});
此函数在 3 个不同的组件中编写了 3 次,用于笔记、待办事项和即将发生的事件。待办事项有一个额外的文档字段,即完成状态,即将发生的事件有一个事件日期字段。
我的项目中也有 firebase 身份验证,我不知道这是否重要。
【问题讨论】:
标签: reactjs google-cloud-firestore async-await