有效搜索/存在()Firestore,而不会耗尽免费配额 [英] Efficiently search/exist() Firestore without exhausting free quota

查看:41
本文介绍了有效搜索/存在()Firestore,而不会耗尽免费配额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个辅助项目,希望让我的用户检查他们的朋友是否有帐户.

I'm working on a side project and want to let my users check if their friends have accounts.

目前,我已经这样实现了:

Currently I've implemented it like this:

  1. 阅读电话联系人中的电子邮件
  2. 浏览电子邮件
  1. 对具有该电子邮件的用户在用户数据库 1 上进行 .get()查询
  2. 如果数据返回,则朋友在平台上并显示邀请按钮

一小时内超出了

  • 免费配额 2
  • 问题是,即使没有数据返回,任何 .get 都被视为读取操作.他们的 doc.exists 只能在 .get 之后进行调整,因此需要读取文档来检查其存在.

    The thing is that any .get is considered a read operation, even if no data comes back. Their doc.exists can only be tun after a .get so a document read is needed to check for existence.

    我确定我忽略了一些显而易见的事情,实际上,我想做的是对 .exist()这样的查询进行查询,而不会耗费"读取.

    I'm sure I'm overlooking something obvious, what I want to do is in essence to an .exist() like query that does not 'cost' a read.

    1:我实际上不是将电子邮件存储在Firestore中,而是将其哈希存储在其中,并且正在查询这些哈希.效果相同,但是它允许我查询不公开真实电子邮件和其他数据的辅助用户数据库.

    1: I'm not actually storing emails in firestore but their hashes, and am querying those. Same effect, but it allows me to query a secondary user database that doesn't expose true emails and other data.

    2:本身并不是想便宜,但是如果该应用开始商业化,那将使计费成为噩梦.

    2: Not trying to be cheap per se, but if this app turns commercial this would make the billing a nightmare.

    推荐答案

    根据您的评论,您说您将联系人保留在内存中,并且对于每个联系人(电子邮件地址),您都在现有的Firestore数据库中搜索匹配项.

    According to your comment, you say that you keep the contacts in memory and for each contact (email address), you search in your existing Firestore database for matches.

    一个小时内超出了免费配额

    Free quota exceeded within an hour

    这意味着您正在Firestore数据库中搜索大量联系人.

    It means that you are searching the Firestore database for a huge number of contacts.

    问题是,即使没有数据返回,任何.get都被视为读取操作.

    The thing is that any .get is considered a read operation, even if no data comes back.

    是正确的.根据有关 Firestore定价的官方文档,它明确指出:

    That's correct. According to the official documentation regarding Firestore pricing, it clearly states that:

    最低查询费用

    对于您执行的每个查询,最低收费为阅读一份文档,即使该查询未返回任何结果.

    There is a minimum charge of one document read for each query that you perform, even if the query returns no results.

    因此,如果您有1000个联系人,并且查询数据库中的每个联系人,即使您的查询未返回任何结果,您仍然要承担1000个读取操作的费用.

    So if you have for example 1000 contacts and you query the database for each one of them, even if your queries return no results, you're still charged with 1000 read operations.

    我确定我忽略了一些显而易见的事情,实际上,我想做的事情是查询.exist()这样的查询,而不会耗费"读取费用.

    I'm sure I'm overlooking something obvious, what I want to do is in essence to an .exist() like query that does not 'cost' a read.

    那不是Firestore的工作方式.这意味着无论结果如何,每个查询都会产生至少读取一个文档的费用.

    That's not how Firestore works. This means that every query incurs a cost of at least one document read, no matter the results.

    1:我实际上不是将电子邮件存储在Firestore中,而是将其哈希存储在其中,并且正在查询这些哈希.效果相同,但是它允许我查询不公开真实电子邮件和其他数据的辅助用户数据库.

    1: I'm not actually storing emails in firestore but their hashes, and am querying those. Same effect, but it allows me to query a secondary user database that doesn't expose true emails and other data.

    正如您已经注意到的那样,无论存储实际的电子邮件地址还是相应的哈希都无所谓,结果是相同的.

    As you already noticed, doesn't matter if you store the actual email address or the corresponding hash, the result is the same.

    2:本身并不是想便宜,但是如果该应用开始商业化,那将使计费成为噩梦.

    2: Not trying to be cheap per se, but if this app turns commercial this would make the billing a nightmare.

    尝试使用此功能, Firebase实时数据库,相信我,两者都可以很好地协同工作在同一个项目中.

    Try for this feature, Firebase realtime database and believe me, both work very well together in the same project.

    这篇关于有效搜索/存在()Firestore,而不会耗尽免费配额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆