iDecode
iDecode

Reputation: 28996

Cloud firestore read count in StreamBuilder

Firebase structure:

enter image description here


Code:

I'm using a StreamBuilder for document uid like this:

@override
Widget build(BuildContext context) {
  return StreamBuilder<User>(
    stream: _stream(), 
    builder: (BuildContext _, AsyncSnapshot<User> snapshot) {
      // this block may get called several times because of `build` function
      if (snapshot.hasData) {
        final user = snapshot.data; 
        return SomeWidget(user: user);
      }
      return CircularProgressIndicator();
    },
  );
}

Questions:

  1. Since StreamBuilder's builder may get called several times because of the build() method, will that cost me a read every time builder gets called?

  2. Is there any difference in terms of read-count when reading complete uid vs reading uid/education?

  3. If I update age and name value, will that count as one-write or two-writes in terms of firebase write-count?

Upvotes: 0

Views: 1255

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80934

Firestore charges on every document read, write and delete therefore:

Since StreamBuilder's builder may get called several times because of the build() method, will that cost me a read every time builder gets called?

Yes, if you are reading(retrieving) one document each time, then you will be charged as one read.

Is there any difference in terms of read-count when reading complete uid vs reading uid/education

No difference. The read is done in the document, when you retrieve one document then you are doing one read.

If I update age and name value, will that count as one-write or two-writes in terms of firebase write-count?

If you update one document once (even if all the fields are updated), it will cost you one write operation.

Upvotes: 0

Related Questions