Firebase用户photoURL和displayName [英] Firebase User photoURL and displayName

查看:78
本文介绍了Firebase用户photoURL和displayName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段时间想把我的脑袋围绕在我认为是一个简单的概念上.

I'm having a time trying to wrap my head around what I thought was a simple concept.

我有一个用于注册用户的应用程序,允许该用户在Firebase Auth系统中为其用户信息设置"photoURL".这行得通.当用户在我的应用中创建帖子时,我想显示标题,图像和 创建者的"photoURL".

I have an app where I sign up a user, allow that user to set a 'photoURL' to their 'user' information in the Firebase Auth system. This works. When the user creates a post in my app, I want to display the title, image and 'photoURL' of the creator.

当前,我保存帖子:

-Post {
 -id
 -title
 -image
 -photoURL <- from current logged in user }

我还允许用户通过路由/poster/'displayName'访问海报页面

I also allow users to visit the posters page via routing /poster/'displayName'

因此,稍后,当用户更新其个人资料信息(例如displayName或photoURL)时,我是否需要查找该用户拥有记录的所有帖子,评论,消息,回复以及其他任何位置并更新photoURL?

So later, when a user updates their profile information like displayName or photoURL, do I need to go find all posts, comments, messages, replies and any other place that this user has a record and update the photoURL?

我想我可以做的是说:(伪代码)

What I thought I would be able to do is say: (pseudo code)

get all posts =>
 foreach(post)
   post = {
          title: post.title.val()
          image: post.image.val()
          avatar: firebase.database().ref().child('users' + post.key)
          }

我读到的所有内容都说我需要将该photoURL存储在我自己的用户"表中.如果这样做,那么除非我编写服务器调用来每次进行更改,否则所有帖子都不会更新.问题是,如果我有10万个用户,而其中有10%的用户更改了他们的photoURL,则必须在每个用户的帖子,评论,答复和消息中对其进行更改.如果普通用户有100条帖子,4000条评论,6000条回复,那么我们正在寻找大约1万个地点*必须更新的1万个用户,如果平均服务器调用时间为137ms,那么我的费用约为175美元(费用)

Everything I read says I need to store that photoURL in my own 'Users' table. If I do that, then none of the posts get updated unless I write a server call to do that every time there is a change. Problem is, if I have 100K users, and 10% of them change their photoURL, I then have to change it in posts, comments, replies and messages per user. If the average user has 100 posts, 4000 comments, 6000 replies, we're looking at about 10K places * 10K users that have to be updated and if the average server call is 137ms, then my costs are around $175 (costs)

另一个选择是每次都从两个表中提取信息并创建一个新对象.这将导致服务器调用和时间大约增加一倍,从而使我的成本增加一倍.

The other option is to pull information from two tables and create a new object every time. This would lead to about double the server calls and time thus doubling my costs.

这是最好的方法吗?我认为仅获取用户照片和显示名称会容易得多.

Is this the best approach for this? I thought this would be a lot easier to just get the user photo and display name.

很抱歉,这是史诗般的长篇文章,但我正在尝试学习.谢谢大家!

Sorry for the epic long post but I'm trying to learn. Thanks all!

推荐答案

使用noSQL数据库时,您所描述的是一个典型问题.一方面,数据重复使您的应用及其查询运行得更快.另一方面,如果要更改任何重复的数据,查找并替换所有出现的数据可能会遇到问题.

What you're describing is a typical issue when working with noSQL databases. On the one hand, data duplication makes your app and its queries run faster. On the other hand, if you want to change any that duplicated data, it can be problematic to find and replace all occurrences.

没有确定最佳方法的最佳"方法.这完全取决于您的具体情况.听起来,如果您有大量的重复数据更新可能成本很高,那么每次仅查询用户记录而不是进行更新会更好.但同样,这最终取决于您.

There's no "best" way to determine what to do. It's completely up to your particular case. It sounds like, if you have extreme amounts of data duplication that could be costly to update, it would be better to simply query the user record every time rather than to do the updates. But again, it's ultimately up to you.

这篇关于Firebase用户photoURL和displayName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆