【发布时间】:2020-04-17 12:57:45
【问题描述】:
我正在使用 Cloud Firestore 设计一个聊天应用程序,架构看起来像这样:
每个 1:1 聊天都是在 chats 集合中创建的。每个 chats 集合都有一组字段和一个子集合。每个子集合将包含所有消息。它看起来像这样 -
/chats
* id (auto gen)
* channel ( string type - sort(uid1 , uid2) )
* uid1
* uid2
* createdTime
* lastMessageSentTime
* messages (sub collection)
* fromUid
* toUid
* content
* sendTime
为了显示初始聊天屏幕,其中包含与用户聊天的所有用户,我查询 /chats 集合并按 lastMessageSentTime 对结果进行排序。
我看到这个设计的一个问题是我需要为每条发送或接收的消息更新 lastMessageSentTime。有什么办法可以避免这种重复写吗?
我可以使用 messages 子集合的 sendTime 以某种方式显示第一个聊天屏幕还是有其他方法?
提前致谢!
【问题讨论】:
标签: firebase google-cloud-firestore