ghufranne
ghufranne

Reputation: 919

Does Using SnapshotParser while querying firestore an expensive operation?

Does using SnapshotParser while querying Firestore an expensive operation in terms of read operation?

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?

Would it be the same operation(in terms of server hit) with or without SnapshotParser?

Please explain, if anything is missed, please let me know? Sorry for bad english.

Upvotes: 1

Views: 872

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138834

From the official documentation of Firebsase-UI library:

If you need to customize how your model class is parsed, you can use a custom 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. 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.

Upvotes: 1

Related Questions