def read_entire_collection(collection) -> dict:
    """Reads an entire Firestore collection as a dict with doc.id as key. Uses batches to avoid timeout."""
    result = {}
    page_size = 10000
    cursor = None
    docs = []
    while True:
        docs.clear()
        count = 0

        query = collection.limit(page_size).order_by('__name__')
        if cursor:
            query = query.start_after(cursor)
        docs = [snapshot for snapshot in query.stream()]
        for doc in docs:
            count += 1
            result[doc.id] = doc.to_dict()
        if len(docs) < page_size:
            break
        else:
            cursor = docs[page_size-1]
        print(f'Read {len(result)} documents from collection...')
    return result