Firestore是否优化为仅读取自上次读取以来发生更改的值?

huangapple go评论74阅读模式
英文:

Is firestore optimized for read by reading only the values that have changed since the last read?

问题

Firestore是否针对读操作进行了优化,仅读取自上次读取以来发生变化的值?

  • Firestore客户端维护一个本地缓存。
  • 缓存中的文档具有带有更新时间戳的元数据,我认为这是服务器上的更新时间戳,而不是本地时间戳。
  • Firestore读取需要付费。

如果上述所有情况都成立,那么Firestore SDK不重新读取自上次读取以来未更新的文档,从带宽和费用的角度来看是更有效的。

Firestore是否默认进行了这种优化,或者它重新查询了所有内容?

英文:

Is firestore optimized for read by reading only the values that have changed since the last read ?

  • Firestore client maintains a local cache.
  • Documents in the cache have metadata with an update timestamp which I assume is the update time stamp on the server and not a local timestamp.
  • Firestore reads cost money.

If all the above holds true, it would make sense for firestore sdk to not re-read documents that have not been updated since the last read, to be more efficient bandwidth wise and dollar wise.

Do firestore optimize this by default or does it requery everything ?

答案1

得分: 3

Firestore 只查询已更改的文档,使用一种称为恢复令牌的机制。来自服务器的结果包括此令牌,可用于以后恢复查询。这实际上是要求自上次查询以来的更改。

然而,在30分钟后,服务器会停止代表客户端跟踪查询的更改(以节省资源)。在此点之后,客户端恢复时,服务器必须重新运行整个查询以查看发生了什么更改。

仅查询最后修改时间的问题在于,您将无法看到任何文档删除。次要问题是,在此类时间戳上创建索引必然会将集合的吞吐量限制为约每秒500次写入。

来源:https://github.com/firebase/firebase-js-sdk/issues/3422

英文:

Firestore only queries for changed documents, using a mechanism known as a resume token. Results from the server include this token which can be used to resume the query at a later time. This implicitly asks for changes since the last query.

However, after 30 minutes, the server stops tracking changes to the query on behalf of the client (to conserve resources). When a client resumes after this point, the server has to re-run the whole query to see what changed.

The problem with just querying for a last-modified timestamp is that you won't see any document deletions. A secondary problem is that creating an index on such a timestamp necessarily limits throughput to the collection to about 500 writes/second.

source: https://github.com/firebase/firebase-js-sdk/issues/3422

huangapple
  • 本文由 发表于 2023年5月28日 07:24:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定