Reputation: 209
I would like to prevent as much write data to firestore and make it as efficient. The user can edit their profile that consists of three sections. The way i have it at the moment is that the firestore update is stored in a method which updates all the sections even if only one section is updated.
I would like it so that if the user only edits one section then that is only updated within firestore.
My code
await firestoreInstance
.collection("users")
.document(firebaseUser.uid)
.updateData({
"images": _imagesUrl,
"name": firstNameController.text,
"biography": biographyController.text,
});
Upvotes: 0
Views: 574
Reputation: 598740
The problem here is that we have no way to know the current value of any of these fields.
If you know the current value, you can compare the current and new values and only send it to the database if they are not the same.
If you don't know the current value, then loading the current value is probably more costly than simply sending all three fields to the database.
The reason for that is that Firebase charges for (in this scenario):
So Firestore doesn't charge bandwidth for data you send to the database. So while only sending modified fields may save bandwidth, it won't save in Firebase cost on that front, while having to read the document to determine what fields are modified will definitely cost more.
Upvotes: 2