Skip to content

Conversation

@thebrianchen
Copy link

No description provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 9, 2020
return this._firestore
.request<api.IBatchWriteRequest, api.BatchWriteResponse>(
'batchWrite',
request as api.IBatchWriteRequest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am leaning towards recommending that you should have two different methods. The new method would be fairly short since we can't support implicit transactions directly.

We should also think about if we need a dummy request for batch writes to make sure the network is initialized.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated out logic into batchCommit() method

writeResult.updateTime
? Timestamp.fromProto(writeResult.updateTime)
: null,
status.code as Status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the status with its error message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an RpcStatus interface to hold the Status, not sure if that's what you were looking for

requestTag?: string;
},
useBatch = false
): Promise<WriteResult[] | BatchWriteResult[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can always return BatchWriteResult. commit() can drop the unused Status.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A since I separated out the logic

Copy link
Author

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated out the BatchWriteRequest logic from commit() into its own method, WDYT?

return this._firestore
.request<api.IBatchWriteRequest, api.BatchWriteResponse>(
'batchWrite',
request as api.IBatchWriteRequest,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated out logic into batchCommit() method

requestTag?: string;
},
useBatch = false
): Promise<WriteResult[] | BatchWriteResult[]> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A since I separated out the logic

writeResult.updateTime
? Timestamp.fromProto(writeResult.updateTime)
: null,
status.code as Status
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an RpcStatus interface to hold the Status, not sure if that's what you were looking for

}

/** Helper type to hold a google.rpc.Status object. */
interface RpcStatus {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the type we actually want to return is GoogleError which exists in GoogleGax and matches your interface. Can you use that type instead? This allows us to use the same type in all Promise rejections.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done inside bulkCommit()

*
* @private
*/
async batchCommit(commitOptions?: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of the name "bulkCommit"? I would like to reduce confusion, and deciding between "commit" and "batchCommit" is going to be tough.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that more -- the hard part was figuring out where to draw the line since we refer to it externally as bulk writes, but the backend API refers to it as batch writes.

@schmidt-sebastian schmidt-sebastian removed their assignment Mar 11, 2020
@thebrianchen
Copy link
Author

@schmidt-sebastian Would you mind taking one last look? made some other changes that I want another look over (using || check, GoogleError usage)

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants