问题
Is it necessary to use the Save data as transactions Technic if a value only increases?. In the example Firebase doc social blogging app the starCount
can go upp or down so it´s logical to use the Transaction Technic right. But if value only increases I suppose the Transaction Technic is not needed right? or?
Multiple users at the same time increasing a value right.
回答1:
The counter can grow up or down, means that a user can click on the counter to increase the value, but can also decrease the value if he clicks again. When we use transactions, we don't use only to increase or decrease a counter, we use if know that in our app is a possibility that two users can make the same action in the same time. If we don't use transactions, the counter can be increased/decreased only by one, in stead of two times, if two users take the action in the same time.
If we use transactions, both actions will take place in different threads of execution, so there is no way in which a counter can be increased/decreased only once, even both users take the same action in the same time.
As a conclusion, use transactions every time you think that is a posibillity that two or more users can change the same value in your Firebase database at the same time.
Hope it helps.
来源:https://stackoverflow.com/questions/44464889/when-to-use-firebase-transactions-or-not