Firebase: Atomic Transactions and Multipoint Updates

I am trying to figure out how to update my data accordingly in Firebase.

My application is a social network. Suppose I need to update the number of views in an object userand in postwhen a visitor enters. I also need to update the value updatedAtin the same objects.

  • Each of the fields views, and updatedAthas a specific authorization .writein child elements post, and userso anyone can modify them, unlike other children.
  • The child viewsmust be updated using transactionto increase the atomic count
  • A child updatedAt, on the other hand, can be upgraded by any means, transaction, setor update.

I would like to limit the number of Firebase calls and make the whole update atomic by combining these updates. (Also because there is still much that I am not describing here)

The problem is this:

  • And transactionfor updating views, this is how it updatedAtshould happen twice: at the objects postsand users, but the visitor cannot write on these objects that are not his own, only two children viewsand updatedAtcan be changed. (even if others are untouched).
  • Multiple location operations are not available in the current Firebase API, AFAIK, therefore it is also not atomic.
  • A multi-axis update for each child will result in loss of atomicity of the child view, which is a problem in a multi-user environment.

In the end, what I'm doing now:

transaction views update updatedAt , posts, users, . !

, views, , .

:

?

+4
1

, updatedAt update(), -out.

, , - .

0

Source: https://habr.com/ru/post/1629176/


All Articles