samuelgozi/firebase-firestore-lite

Commit doesn't seem to follow BeginTransaction call and PreConditions

Closed this issue · 4 comments

this.preconditions = {};

I noticed that the preconditions for a read-write transaction are ignored intentionally. Also there is not BeginTransaction call for a starting a transaction.

Commit call as per the rest api expects a transaction identifier(returned from BeginTransaction). Ideally giving some info to commit about when a prior read makes sense.

Can you please clarify If i'm missing something or perfect transactions(ReadFollowedByWrties) are not supported?

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.68. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Sorry for the late reply.
They are not ignored. They are being reset when the commit() method is called.
The internal preconditions property is used when one of the following methods is called:

  1. tx.add
  2. tx.set
  3. tx.update
  4. tx.delete

These methods check for preconditions (when applicable).
Every time a read is done within a transaction (by using tx.{METHOD}), and a write is done on that document, the precondition is used.
You can find the logic in the write method in the Transaction.ts file.

If my explanation wasn't clear, please let me know.

Thanks for the clarification.
I was going through the REST API and found BeginTransaction endpoint.

Any reasons where we need to use it and pass the transaction string in commit call?

If you need for some reason to start making changes in small batches, then it might be useful. If I remember correctly you will have a window of 60 seconds to do it. But I couldn't think of a good use-case for it.