Python 如何防止第二个for循环减慢从服务返回的数据

Python 如何防止第二个for循环减慢从服务返回的数据,python,django,firebase,google-cloud-firestore,Python,Django,Firebase,Google Cloud Firestore,我正在django应用程序中使用firestore获取数据 查询流工作得很好 我正在尝试进行一些关系查询,从另一个表中获取post的作者 我不确定这是不是django的做法 以下是我的代码: # Get Updates Method def get_updates(): # Get Updates From Firestore user_ref = firestore_client.collection('post') query = user_ref.where('st

我正在django应用程序中使用firestore获取数据

查询流工作得很好

我正在尝试进行一些关系查询,从另一个表中获取post的作者

我不确定这是不是django的做法

以下是我的代码:

# Get Updates Method
def get_updates():
    # Get Updates From Firestore
    user_ref = firestore_client.collection('post')
    query = user_ref.where('status', '==', 'online').order_by('updatedAt', direction=firestore.Query.DESCENDING)

    # Updates Lists
    updates = []

    # For Loop to get stream into list and change date strings to django friendly
    for doc in query.stream():
        updates.append(doc.to_dict())
        for update in updates:
             # Get Update Author
             author_ref = firestore_client.collection('users').document(update['uid'])
             author = author_ref.get()
             if author.exists:
                update['name'] = author.get('displayName')
                update['avatar'] = author.get('photoURL')
             update['createdAt'] = datetime.strptime(doc.get('createdAt'), '%Y-%m-%d %H:%M:%S')
             update['updatedAt'] = datetime.strptime(doc.get('updatedAt'), '%Y-%m-%d %H:%M:%S')
第二个for循环增加了加载时间。页面加载后,我得到了想要的结果,但速度太慢。
这样做的有效方法是什么

你考虑过为firestore寻找ORM吗?你有什么建议吗?