-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start writing new commits/tasks to Firestore #3472
Start writing new commits/tasks to Firestore #3472
Conversation
/// This is an atomic operation: either all writes succeed or all writes fail. | ||
Future<CommitResponse> writeViaTransaction(List<Write> writes) async { | ||
final ProjectsDatabasesDocumentsResource databasesDocumentsResource = await documentResource(); | ||
final BeginTransactionRequest beginTransactionRequest = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some databases have multiple commit modes. Is there anything in Firestore where you don't have to manage the commits manually like with with transactions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a transaction operation, a commit is explicitly needed. There are other operations like batchWrites
, which doesn't need a commit.
BeginTransactionRequest(options: TransactionOptions(readWrite: ReadWrite())); | ||
final BeginTransactionResponse beginTransactionResponse = | ||
await databasesDocumentsResource.beginTransaction(beginTransactionRequest, kDatabase); | ||
final CommitRequest commitRequest = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If commit fails do we need a rollback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transaction acts as an atomic operation. If it fails, everything will auto roll back.
List<Document> targetsToTaskDocuments(Commit commit, List<Target> targets) { | ||
final Iterable<Document> iterableDocuments = targets.map( | ||
(Target target) => Document( | ||
name: '$kDatabase/documents/tasks/${commit.sha}_${target.value.name}_1', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the significance of the '_1'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using _1
to track the old attempt
logic. We want to keep all the records of retries, instead of overriding using a single record.
(Target target) => Document( | ||
name: '$kDatabase/documents/tasks/${commit.sha}_${target.value.name}_1', | ||
fields: <String, Value>{ | ||
'builderNumber': Value(integerValue: null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this can be nullable? Is this the main identifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this might be updated at a later date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. We will update the entry later when status changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR
Part of flutter/flutter#142951.