0

I'm trying to understand the Cloud Firestore read quota. I have read this post and the response to it. My console was open, but I cannot construe how a single collection with 3 documents, each having 2 attributes constitutes a "busy console".

I'm struggling to make sense of the documentation.

I have one collection in firestore. It has 3 documents. Each document has 2 attributes.

In localhost, I have been running the form to test getting those attributes into an Autocomplete select menu, using a single snapshot.

import React, { useState, useEffect } from 'react';
import Checkbox from '@material-ui/core/Checkbox';
import TextField from '@material-ui/core/TextField';
import Autocomplete from '@material-ui/lab/Autocomplete';
import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';
import CheckBoxIcon from '@material-ui/icons/CheckBox';
import firebase from "../../../../../firebase";

const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
const checkedIcon = <CheckBoxIcon fontSize="small" />;

export default function CheckboxesTags() {
  const [orgList, setOrgList] = useState([]);
  const [selectedOrgList, setSelectedOrgList] = useState();
  const [loading, setLoading ] = useState(true);
  const [ error, setError ] = useState(false);

  useEffect(() => {
    // if (doc.exists) {
      const unsubscribe = firebase
        .firestore()
        .collection("organisations")
        .onSnapshot((snapshot) => {
          const orgList = snapshot.docs.map((doc) => ({
            id: doc.id,
            shortName: doc.data().shortName,
            location: doc.data().location
          }));
          setOrgList(orgList);
        }, () => {
          setError(true)
        });
        setLoading(false);
        return() => unsubscribe();
     
    
  }, [orgList]);



  return (
      <div>
      
        <Autocomplete
        multiple
        id="orgList options"
        options={orgList}
        disableCloseOnSelect
        getOptionLabel={(option) => option.shortName}
        renderOption={(orgList, { selected }) => (
            <React.Fragment>
            <Checkbox
                icon={icon}
                checkedIcon={checkedIcon}
                style={{ marginRight: 8 }}
                checked={selected}
            />
            {orgList.shortName}  
            {orgList.location}
            </React.Fragment>
        )}
        style={{ width: 500 }}
        renderInput={(params) => (
            <TextField {...params} 
            variant="outlined" 
            label="Select Organisation" 
            placeholder="Acme Inc." 
          />
        )}
        />
    </div>
  );
}

I had understood that the snapshot was only supposed to run when there is new data. I have toggled names and fields inside those 3 documents about 20 times today. Each time, I have run the form to test it.

This console usage says I have run 53k reads today. How is that possible?

enter image description here enter image description here

Mel
  • 2,481
  • 26
  • 113
  • 273
  • 1
    You almost certainly left the Firebase console open on a busy collection and it incurred the reads as it updated the UI in real time. – Doug Stevenson Jul 20 '20 at 23:45
  • How can it update reads if the the snapshot is only supposed to run when there is a change to the collection? There is one single collection, with 3 documents, with each having 2 attributes. How does that make a console busy? – Mel Jul 21 '20 at 00:50
  • With what you're showing here, it's not clear. In fact, there are no tools to figure out where your rules are coming from. If you think the accounting is wrong, contact Firebase support. But I suspect that it's not wrong, and there's something going on here that you'll have to track down. Stack Overflow is not well suited to help with this, as we don't have visibility in to your project, and we don't know how to reproduce the issue. Almost 100% of the time, overages on reads are due to the console, though. – Doug Stevenson Jul 21 '20 at 01:07
  • 1
    Your comments are noted. Your actions have prevented others, who may have relevant insights to share, from engaging with this post. Thankfully, stack overflow is largely a generous community of people with diverse experience and capacity to assist. – Mel Jul 21 '20 at 23:31
  • 1
    For others seeing this post and who do not agree that it is a duplicate of the tagged post, you can find helpful input and insights on this post: https://stackoverflow.com/questions/63009673/react-hooks-with-firestore-data-1-1k-reads-in-30-seconds-from-2-collections-w – Mel Jul 31 '20 at 21:34

0 Answers0