Firebase User photoURL and displayName

青春壹個敷衍的年華 提交于 2019-12-30 11:22:11

问题


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

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.

Currently, I save the post:

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

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

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)
          }

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!


回答1:


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.



来源:https://stackoverflow.com/questions/47334382/firebase-user-photourl-and-displayname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!