简体   繁体   English

Swift Firebase更新旧数据-实时数据库触发器

[英]Swift Firebase update old data - Real Time Database Triggers

In the below image I have messages in my app, yet when a user say updates their profile image or name the data below becomes stale data. 在下面的图像中,我的应用程序中有消息,但是当用户说要更新其个人资料图像或命名时,下面的数据将成为过期数据。 I have come across "Firebase Functions" and see that I can keep this data in-sync if I use Firebase Functions. 我遇到过“ Firebase Functions”,并且看到如果使用Firebase Functions,可以保持此数据同步。 Yet, only knowing Swift I am unsure how to implement Firebase Functions to keep my messages in-sync which the changing data in the user profiles. 但是,仅了解Swift我不确定如何实现Firebase功能来保持我的消息与用户配置文件中不断变化的数据保持同步。 Can someone help me point in the right direction on how I implement this into my project? 有人可以帮助我指出如何将其实施到项目中的正确方向吗? Haven't found any sample code in swift or any tutorials for that matter. 尚未在swift或任何教程中找到任何示例代码。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

在此处输入图片说明

在此处输入图片说明

Based on the comments and the structure in the question, the reason the data is becoming stale is due to how the data is stored in Firebase. 根据评论和问题的结构,数据变得过时的原因是由于数据如何存储在Firebase中。

One option is that when a message is sent, a node is written with the message and then a reference to the senders info. 一种选择是,当发送一条消息时,节点将被写入消息,然后是发件人信息的引用 That keeps everything fresh and up-to-date at all times 这样可以使所有内容始终保持最新

So say we have a users node with users stored with the users UID as the key to each node 可以这么说,我们有一个用户节点,其中的用户存储有用户UID作为每个节点的键

users
   uid_0
     user_name: "Peter"
     user_age:  "32"
     gender:    "Male"
     business_name: "Peter's Plumbing Place"
     url: "http:...."
     type: "Customer"
   uid_1
     user_name: "Ralph"
     user_age:  "47"
     gener:     "Male"
     business_name: "Ralph's Repair Room"
     url: "http:...."
     type: "Employee"

then we have messages 然后我们有消息

messages
   msg_0
     msg_text: "Here's a message!"
     from_uid: "uid_0"
     to_uid:   "uid_1"
     timestamp: "20180110"

Then, user uid_1 adds a query observer to the messages node for any messages where to_uid is uid_1 so they are notified of the incoming message. 然后,用户uid_1将toto uid为uid_1的任何消息的查询观察者添加到消息节点,以便将传入消息通知给它们。 When they receive it, they will also know it was sent by uid_0 and can pull up their name, profile image, age etc. 当他们收到它时,他们还将知道它是由uid_0发送的,并且可以提取其姓名,个人资料图像,年龄等。

That way, all data is kept in sync and current and no stale data exists. 这样,所有数据将保持同步和最新状态,并且不存在陈旧数据。

This is a typical implementation of a structure for a messaging app. 这是消息传递应用程序结构的典型实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM