简体   繁体   English

在查询 firestore 时使用 SnapshotParser 是否是一项昂贵的操作?

[英]Does Using SnapshotParser while querying firestore an expensive operation?

Does using SnapshotParser while querying Firestore an expensive operation in terms of read operation?就读取操作而言,在查询 Firestore 时使用SnapshotParser是否是一项昂贵的操作?

We are building query in our app like this:我们正在像这样在我们的应用程序中构建查询:

  options = new FirestoreRecyclerOptions.Builder<Item>()
                    .setQuery(query, new SnapshotParser<Item>() {
                        @NonNull
                        @Override
                        public Item parseSnapshot(@NonNull DocumentSnapshot snapshot) {
                            Item item = snapshot.toObject(Item.class);
                            item.setId(snapshot.getId());
                            return item;
                        }
                    })
                    .setLifecycleOwner(this)

So while reading data from server, does SnapshotParser will make extra read operation (or hit server again) or it will parse using already read data?那么在从服务器读取数据时, SnapshotParser会进行额外的读取操作(或再次命中服务器)还是会使用已经读取的数据进行解析?

Would it be the same operation(in terms of server hit) with or without SnapshotParser?使用或不使用 SnapshotParser 是否是相同的操作(就服务器命中而言)?

Please explain, if anything is missed, please let me know?请解释一下,如果有遗漏,请告诉我? Sorry for bad english.抱歉英语不好。

From the official documentation of Firebsase-UI library:来自Firebsase-UI库的官方文档:

If you need to customize how your model class is parsed, you can use a custom SnapshotParser.如果需要自定义模型类的解析方式,可以使用自定义 SnapshotParser。

So if you need to customize your model class it doesn't mean that you are creating extra read operations.因此,如果您需要自定义模型类,并不意味着您正在创建额外的读取操作。 The parseSnapshot() method uses as an argument a DocumentSnapshot object which contains the data set that you are getting from the database for which you are already charged in terms of read operations. parseSnapshot()方法使用DocumentSnapshot对象作为参数,该对象包含您从数据库中获取的数据集,您已经为其读取操作parseSnapshot() This is happening if the the query return data.如果查询返回数据,就会发生这种情况。 If your query does not return any data, you are still charged but only with a single read operation.如果您的查询未返回任何数据,您仍需付费,但只需执行一次读取操作。

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

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