简体   繁体   English

Firestore 读取、写入和删除如何计算?

[英]How are Firestore reads, writes and deletes counted?

I'm not sure if I understand Firestore reads, writes, and deletes correctly.我不确定我是否正确理解 Firestore 的读取、写入和删除操作。 I think the best way I would understand is if I got clarification, correction, or answers of the total reads, writes, or deletes per action on the following questions below.我认为我能理解的最佳方式是,如果我对以下问题的每次操作的读取、写入或删除总数得到澄清、更正或答案。 I'm using Next.js我正在使用 Next.js

Q: If I add collection with document no matter how many fields , does it count as 1 write, or does it count how many collection , documents , and total fields we wrote? Q:如果我添加collection with document不管多少fields ,算1 write,还是算我们写多少collectiondocuments 、total fields And is it the same logic for reading and delete?读取和删除的逻辑是否相同?

Current setup for a project:项目的当前设置:

LOGIN登录

I'm currently using Google sign-in provider as sign-in method.我目前正在使用 Google 登录提供程序作为登录方法。

Everytime a user logs in useEffect renders and setDoc on "Users" collection , user.uid document :每次用户登录时, useEffect会在“Users” collection 、user.uid document上呈现和setDoc

user: {
  //Default Firebase Authentication info
}

The header component(outside of layout) is then updated with:然后将 header 组件(布局外部)更新为:

user.photoURL

user.displayName

Q: How many reads and writes for every time a user logs in? Q: 用户每次登录的读写次数是多少?

POSTS帖子

On HomePagePosts component(inside layout) 10 recent posts are fetched from "Posts" collection .在 HomePagePosts 组件(内部布局)上,从“帖子” collection中获取 10 个最近的帖子。 Every post include:每个帖子包括:

user.photoURL
post.title
post.description
post.createdDate
postURL.postID

If currently, a logged-in user created any of the 10 posts, an edit & delete button is shown.如果当前,登录用户创建了 10 个帖子中的任何一个,则会显示一个编辑和删除按钮。 For my question, let's say 2 of the posts were created by currently logged-in users.对于我的问题,假设其中 2 个帖子是由当前登录的用户创建的。

Q: How many initial reads for the 10 posts?问:这 10 个帖子的初始阅读量是多少?

CREATE POST:创建帖子:

When user goes to createpost page useEffect renders and checks if "Posts" collection , user.uid document , "Folder" collection .length > 0.当用户进入 createpost 页面时, useEffect渲染并检查“Posts” collection 、user.uid document 、“Folder” collection .length > 0。

If Folder length not greater than 0, CreateFolder component displays, it includes:如果 Folder length 不大于 0,则显示 CreateFolder 组件,它包括:

folder.name

folder.type //local JSON file

When a folder is created its added to "Users" collection , user.uid document , "Folders" collection , then useEffect renders again.创建文件夹后,将其添加到“Users” collection 、user.uid document 、“Folders” collection ,然后再次渲染useEffect

If Folder length greater than 0, Folder component shows a list of folders.如果文件夹长度大于 0,文件夹组件显示文件夹列表。

When user creates the post document is added to "Posts" collection with:当用户创建帖子document时,将添加到“帖子” collection中:

post.title
post.description
post.content
postCategory.selectedFolder.type
folder.{
  folder.name
  folder.type
}
tags.{
  (lets say 2 tags)
}

Q: How many reads and writes for 1 post created and 1 folder created within?问:创建的 1 个帖子和其中创建的 1 个文件夹的读写次数是多少?

It doesn't really matter how many fields an object has, when you perform a write operation in Firestore, you'll have to pay a single write. object 有多少字段并不重要,当您在 Firestore 中执行写入操作时,您必须支付一次写入费用。 This works only if the rules allow that write and only if the document is within the 1 MiB limit, otherwise will fail.这仅在规则允许写入并且仅当文档在1 MiB限制内时才有效,否则将失败。 The same rule applies to the reads and deletes you perform.相同的规则适用于您执行的读取和删除。

If you want to reduce the costs, you might be interested in reading this article:如果你想降低成本,你可能有兴趣阅读这篇文章:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM