Clay Banks
Clay Banks

Reputation: 4591

Automatically Updating Stale Data in Firebase

I have a social networking structure in my Firebase Database that provides a user following system

user-followers
  -F2iRZkwfuTcKUvd7uYD0jwWeJ7T2
    -KgkkWy5xesvcFcL9GMh: 
      -username: 'billybob'
      -fullName: 'Billy Robertson'
    -KgkoZpD0GP687J_5Zh5: true
      -username: 'coolguy55'
      -fullName: 'Jim Davis'

This works fine for reading a summarized view of a given user's followers. However, when a user updates their profile, say their username or fullName, the data under user-followers immediately becomes outdated.

Is there any feasible solution to keeping this nested data updated, without writing an extra function when a user's profile is updated? To me this seems unavoidable

Any input is appreciated!

Upvotes: 1

Views: 1714

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317760

You could use Cloud Functions for Firebase to write a database trigger that runs in response to writes that happen in one place in your database so that other changes can be made to keep things consistent where data needs to be duplicated.

Upvotes: 2

Related Questions