Home > OS >  is this too many requests?
is this too many requests?

Time:09-06

So I'm making an application where each time the user touch the screen the counter is incremented by one this is how it is incremented in the code below. is there a better way to increment the counter while saving it in the database without sending so many requests but also making sure that it will be the same if the user closed or signed out etc..

void _incrementCounter(){
setState(() {
  count  ;
});
FirebaseFirestore.instance.collection('user').doc(uId).update({'count': FieldValue.increment(1)});

CodePudding user response:

If you want to have up-to-date data, then I would do that after each increment, yes.

But you could also store the number of clicks in the shared preferences and send this value every x seconds/minutes/hours.

CodePudding user response:

In my opinion, making requests per touch is not efficient.¯\(ツ)/¯ Instead, you should store it in a variable and then add it to the firebase value after a particular time interval.

  • Related