Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore collection listeners enormous number of reads

I am implementing Firestore data storage in one of my apps.

I have a listener which follows updates in the "logs" collection like so:

db.collection("logs").addSnapshotListener({ (snapshot, error) in
    guard let s = snapshot else {return}
    if s.metadata.isFromCache {
        print("LOG_C \(s.documentChanges.count)")
            return
    }
    print("LOG \(s.documentChanges.count)")
    // other code
})

During testing, I've been uploading documents to this collection and then I removed all of them through Firebase console. So, right now, the collection doesn't exist for my test user. When I launch the app for the first time, I do see that this collection is empty - the listener reports the correct result.

However, in doing so, it consumes roughly 1000 reads. It almost feels like it is downloading all the history of this collection for my test user (e.g. 500 docs inserted, 500 docs deleted). However, even if it does, it does not report it to me - I receive only one "LOG 0" message in the console.

Is this how collection listeners work? I do know that listeners download the initial state, but I thought that it would be the current snapshot which, in this case, would consume 1 read to determine that there is nothing to return initially.

Any explanations/ideas/suggestions are welcome.

I would very much like to debug this by viewing detailed Firestore read logs. However, I cannot find such option in the console :(

like image 558
Andriy Gordiychuk Avatar asked Feb 26 '19 14:02

Andriy Gordiychuk


People also ask

How big can a collection be firestore?

There is no limitation on the number of documents in Firestore collection but it has a limitation of the size of the document. The maximum size of a document is roughly 1 MiB (1,048,576 bytes).

What is the limited depth of Subcollection in firestore?

I saw on the Firebase Firestore documentation that the limits for the "Maximum depth of subcollections" is 100.


1 Answers

In this case, it sounds as if the OP left the Firestore console open while performing database operations. Since the Firestore console itself reflects realtime updates, it will incur reads over time as the currently selected collection changes.

like image 145
Doug Stevenson Avatar answered Sep 30 '22 17:09

Doug Stevenson