0
votes

I`m just creating a Instagram clone app for testing

my data structure is below

   --- users (root collection)
         |
         --- uid (one of documents)
              |
              --- name: "name"
              |
              --- email: "[email protected]"
              |
              --- following (sub collection)
              |        |
              |        --- uid (one of documents)
              |            |
              |            --- customUserId : "blahblah"
              |            |
              |            --- name : "name"
              |            |
              |            --- pictureStorageUrl : "https://~~"
              |
              --- followers (sub collection)
              |        |
              |        --- uid (one of documents)
              |            |
              |            --- customUserId : "blahblah"
              |            |
              |            --- name : "name"
              |            |
              |            --- pictureStorageUrl : "https://~~"
              |

Assume user A has 1 million followers and then if user A edits a picture or name or customUserId, should the document of each sub collection "following" of 1 million followers users be modified?

Should there be 1 million updates? Are there any more efficient rescue methods? And if there is no other good way, is it appropriate to batch data modification through the database trigger of the cloud function in the case of the above method?

1

1 Answers

3
votes

Should the document of each sub collection "following" of 1 million followers users be modified? Should there be 1 million updates?

That's entirely up to you to decide. If you don't want to update them, then don't. But if you want the data to stay in sync, then you will have to find and update all of the documents where that data is copied.

Are there any more efficient rescue methods?

To update 1 million documents? No. If you have 1 million documents to update, then you will have to find and update them each individually.

And if there is no other good way, is it appropriate to batch data modification through the database trigger of the cloud function in the case of the above method?

Doing the updates in Cloud Functions still costs 1 million updates. There aren't any shortcuts to this work - it's the same on both the frontend and the backend. Cloud Functions will just let you trigger that work to happen on the backend automatically.

If you want to avoid 1 million updates, then you should instead not copy the data 1 million times. Just store a UID, and do a second query to look up information about that user.