google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

Firestore: Support returning the commit time from RunTransaction

Open galenwarren opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. When a transaction is performed in Firestore via RunTransaction, the underlying commit operation returns a CommitResponse, which contains the "commit time", as described here. This response - including the commit time -- is ignored in the RunTransaction code, here.

I would like to have access to the commit time. As described in the link above:

Cloud Firestore guarantees serializable isolation of transactions. Transactions in Cloud Firestore are serialized and isolated by commit time.

My particular use case involves building and maintaining a data cache. Similar timestamps are available already DocumentSnapshot and QuerySnapshot.

Describe the solution you'd like Add a new TransactionOption -- GetCommitTime -- that would allow the caller to provide the address of a time.Time where the commit time should be recorded upon successful commit.

Describe alternatives you've considered If a new TransactionOption isn't used, the only other way to get the commit time would be to change the signature of RunTransaction or add a new method (RunTransactionWithCommitTime?) with a different signature. Those options seem messier, to me.

Additional context I have this implemented in a fork and would be happy to contribute the code. Thanks.

galenwarren avatar Oct 11 '22 21:10 galenwarren