Home > database >  Flutter Firebase delete function with httpsCallable
Flutter Firebase delete function with httpsCallable

Time:02-17

I'm creating Flutter app using Firebase as backend. My app is SNS app like Insta, Facebook.

User can create their own card and other user can reply on there. I finished works for creating & deleting card using Firebase.

In case of creating function, they are in user-side(App), and in case of deleting function, I put them into Firebase functions.

My question is about Deleting functions is Firebase. I used "FirebaseFunctions.instance.httpsCallable" to call the function in Firebase. The function which "FirebaseFunctions.instance.httpsCallable" calls from Firebase works like below flow.

----------start

  1. read Card data

  2. find writer of this card > update user information to remove data which this user created.

  3. find users who press likes on this card > update user information to remove data which this user liked.

  4. find users who replied on this card > update user information to remove data which this user liked.

  5. if there is re-reply card on the reply card, repeat this process for that reply card

----------end

But the problem is it takes quite long time. After user press the delete button, it take 1~3min to delete whole data. And if it takes this much longer, other user can reply on this card again before fully it is fully deleted and then I don't know what gonna be happend...

I think if I put this delete function into user-side(App), it would not be takes long as much as this.

Please give me your opinion about why this flow takes so long time and give me a good counter proposer

CodePudding user response:

It's hard to be certain why the deletion takes so much time without seeing the code for it.


In general, you'll want to mark the card as "deleted" as step 0, so before even starting the other work, by writing a special value to it. In all your other actions, always check if a card is marked as deleted before taking any operation on it.

The card is from that point on referred to as a tombstone, as it indicates an object that no longer is supposed to exist for the app.


Finally, consider performing the operations on the top-level card(s) in a transaction, so that they are automatically rejected and retried when a user likes the card while you're updating it.

You can also repeatedly perform the delete operation (on non-tombstoned cards), until there are no more cards to process.

  • Related