0

I finished a block of code that performs 1 write and I noticed that while I did that the app did 16 reads. Is there a fast way for me to see what is causing these reads besides going line by line through my whole app?

enter image description here

The code that does the write is below.

void createGroupFS(String groupName) async {
    final String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
    final currentUID = getUID();
    final currentUsername = await getUsernameFS();

    //Create Firestore records, one for the groups collection and one for the groups_UID collection
    FirebaseFirestore firestore = FirebaseFirestore.instance;
    CollectionReference groupsCollection = firestore.collection('groups');
    final docRef = groupsCollection.doc();

    await docRef.set({
      'adminUID': currentUID,
      'adminUsername': currentUsername,
      'createDate': timestamp,
      'groupID': docRef.id,
      'groupName': groupName,
    }).then((value) => print('##MyApp## database createGroupFS groups record added'))
    .catchError((error) => print('##MyApp## database createGroupFS ERROR: ' + error.toString()));
  }
whatwhatwhat
  • 1,991
  • 4
  • 31
  • 50
  • 3
    How did you "notice" this? Please edit the question to show your code and be clear about what your observations are and how we can reproduce them. Firestore does not have any way to audit reads and writes other than what you see in the console. – Doug Stevenson Sep 14 '22 at 03:46
  • 1
    A quick guess is that you have the Firebase console open to show documents in Firestore, and that also performs read operation. Close the documents, show only the usage tab, refresh the app a few times, wait a few minutes and *then* check the usage tab again. – Frank van Puffelen Sep 14 '22 at 03:48
  • Do you happen to have a FutureBuilder where the "future:" argument is where you're creating the future, instead of just referencing it? – Randal Schwartz Sep 14 '22 at 04:23
  • Please edit your question and add the information Doug asked for, and please also respond using @. – Alex Mamo Sep 14 '22 at 09:46
  • @AlexMamo the app opens to the home page. There is a button there that opens a dialog box. I enter the parameter needed, then press ok. The code above then runs, creating a record in Firestore. – whatwhatwhat Sep 14 '22 at 21:46
  • @DougStevenson modified the question. – whatwhatwhat Sep 14 '22 at 21:46
  • 1
    We can't really say anything for sure given what you've shown here. Either you are running that function a lot of times in a way that we can't see, or your console is open on a collection that's responding to realtime document changes. – Doug Stevenson Sep 14 '22 at 21:51
  • @FrankvanPuffelen without looking at the Data tab and only refreshing the Usage tab, I now only get 1 write and 1 read. 1 read is better than 16 reads for an action that shouldn't be doing any reads at all, but...I'm still curious...idk – whatwhatwhat Sep 15 '22 at 02:35

0 Answers0