loading...

re: Building a news feed with Firebase VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Understood, thanks! I have looked into Redis before, but to be honest I don't want to complicate even more. I just want to implement the best possi...
 

Oh I wasn't suggesting adding Redis, I was just referencing an article that can give you some ideas on how you might approach the problem.

If you really want to optimize for end-user performance, I'd recommend looking at fan-out on write. Fan-out on write essentially guarantees your "feed" reads will become O(1) instead of O(n). Note that your writes, will become O(n), but if you defer the fan-out to a Cloud Function, then the end-user performance doesn't take a hit at all.

Yep, my current implementation is already in O(1) since posts from the users a user is following is stored on a their "timeline" field where posts are referenced through their IDs. Because of this when the app actually loads in all the post data on the timeline, it can be a bit slow. Any way I can cache the existing data so the app shows the cached data on initial load, and then loads in the "new" data once that's ready?

posts from the users a user is following is stored on a their "timeline" field where posts are referenced through their IDs

If the client needs to do an additional "Find Post By ID" call for each ID referenced in the timeline list, then the function getMyTimelinePosts() would be at least O(n). The way around this is to "fan out" copies of the full posts into each user's timeline object. When you make that first call, everything you need for the timeline will be in the response - no additional calls are necessary. Here is another article that helps explain it.

Any way I can cache the existing data so the app shows the cached data on initial load, and then loads in the "new" data once that's ready?

Like this.

Thank you for the help :)

Code of Conduct Report abuse