0
votes

I have encountered some issue when trying to figure out and calculate the firestore read count. The firestore read count is always surging up at a very high rate (100 counts increment every time I reload the page) even though there are only around 15 users documents. Even when I am not reloading the page, the firestore read count would go up itself, is this due to the subscribe behaviour that cause the read data action refreshing from time to time? (I have read some articles recommend to use "once" if user want to extract data just once).

Bellow is the code snippet (ts):

  // All buddy users from Firebase
  private usersCollection: AngularFirestoreCollection<Profile>;
  users: Observable<Profile[]>;
  usersFirebase: Profile[] = [];

getUserDataFromFirebase() {
  this.isImageLoading = false;
  this.users.subscribe(async results => {
      var ref;
      for(let result of results) {
        if(result.imageName) {
          ref = this.store.ref('images/' + result.userId + '/profiles/' + result.imageName);
        } else {
          // Get default image is image not existing
          ref = this.store.ref('images/ironman.jpg');
        }
  
        await ref.getDownloadURL().toPromise().then(urlString => {
          result.profileURL = urlString;
          // Change availibility date from timestamp to date format
          try {
            result.availability = this.datePipe.transform(result.availability.toDate(), 'yyyy-MM-dd');
          } catch (error) {}
          result.flip = 'inactive';


            if(result.identity == 'Tenant')
            {
              this.usersFirebase.push(result);
            }
            return new Promise((resolve, reject) => {
                resolve();
              })
        });
      }
      console.log(this.usersFirebase);
    });
  }

How does the firestore read count works, is the count increment based on document queries, will it continue to query itself after a certain amount of time? Firestore read count increases more than users documents

1
The first thing to keep in mind is that any documents shown in the Firestore console also count towards your reads, so you'll want to close the console during these tests. - Frank van Puffelen

1 Answers

0
votes

The reads counts are focused on the number of documents retrieved.

Lets set these 4 scenarios:

  • A collection of 10 users, you run a collection("users").get() call: you will get back 10 employee documents, and be charged for 10 reads.
  • A collection of 10,000 users, you run a collection("users").get() call: you will get back 10,000 users, and be charged for 10,000 reads.
  • A collection of 10,000 employees, you run a collection("users").get().limit(10) call: you will get back 10 users, and be charged for 10 reads.
  • A collection of 10,000 users, 15 of which are named "Carl" and you run a collection("users").where("first_name", "==", "Carl") call, you will get back 4 users and be charged for 15 reads.

On the other hand, if you are listening to the whole collection users (no where() or .orderBy() clauses) and you have an active onSnapshot() listener then you will be charged for a document read operation each time a new document is added, changed, or deleted in the collection users.

You might want to take a look into your workflow to check whether other process are making changes on your collection when checking the read operations.

Finally, something to keep in mind is that the read ops in your report might not match with the billing and quota usage. There is a feature requests in the Public Issue Tracker realted to this inquiry - reads on Firestore: here. You can "star" it and set the notifications to get updates on them. Also, you can create a new one if necessary.