Firestore-仅在大型同步集合中获取更改的文档 [英] Firestore -- Get only the changed documents in a large synced collection

查看:66
本文介绍了Firestore-仅在大型同步集合中获取更改的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了以下所有问题,并且在文档中找不到任何内容来描述如何同步集合并仅从集合中接收 个更改过的文档.我的同步收藏集中有500多个文档(使用 redux-saga-firebase syncCollection ),但通常只有其中的100处发生变化.在任何给定的时间,更改的次数都会更少,但是即使有一个更改,我现在也会得到所有500 + 个文档,这将导致500多个读取.不太理想,会花我很多钱.

I've read all of the questions below, and cannot find anything in the docs to describe how to sync a collection and receive only changed documents from a collection. I've got over 500 documents in my synced collection (using redux-saga-firebase syncCollection) but usually only about 100 of them ever change. At any given time, even fewer will change, but I'm currently getting all 500+ documents back when even one changes, which results in 500+ reads. Not ideal, and will cost me at scale.

这是我使用redux-saga-firebase的代码,但是也可以使用普通的firebase代码答案.如何获得同步响应,该响应仅发送 集合中已更改的文档?

Here is my code using redux-saga-firebase, but a vanilla firebase code answer would also suffice. How can get a synchronized response that sends only the changed documents in the collection?

export function* getPlayersFromDb() {
  yield fork(
    rsf.firestore.syncCollection,
    'players',
    { successActionCreator: response => ({
            type: t.GET_PLAYERS_FROM_DB_SUCCESS,
            payload: [...response],
        }),
        failureActionCreator: () => ({
            type: t.GET_PLAYERS_FROM_DB_FAILURE,
            payload: [],
        }),
        transform: response => messageTransformer(response),
    }
);

}

Firestore是否仅同步diff?

在Firestore上与大型集合进行领域同步-建筑问题/问题

如何避免使用Cache进行不必要的Firestore读取

Firestore同步到底能做什么?

推荐答案

Firestore查询没有查询仅已更改的事物"的概念.您将需要自行创建该概念.这样做的通常方法是,在每个文档中记录一个时间戳记及其上次更新的时间,然后使用范围过滤器中的该字段仅获取自收到最新更新以来更新的文档.您将需要在客户端中跟踪最新的更新时间戳.一种可能性是使用迄今为止任何文档中看到的最大时间戳.

Firestore queries don't have a notion of querying "only things that have changed". You will need to create that notion on your own. The usual way to do this is by recording a timestamp in each document with the time it was last updated, then using that field in a range filter to get only documents updated since the latest update was received. You will need to track that latest update timestamp in the client. One possibility is to use the greatest timestamp seen in any document to date.

这篇关于Firestore-仅在大型同步集合中获取更改的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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