Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Snapshot class in handwritten/spanner/src/transaction.ts by introducing a private helper method, _applyAffinityGaxOpts, to handle binding the multiplexed session affinity key to outgoing request options. It also adds unit tests to ensure that request and requestStream remain usable when detached and that caller-supplied options are not mutated. The review feedback highlights two key improvements: first, to prevent accidental mutation of the shared internal configuration, this._bindGaxOpts should be deep-copied rather than directly assigned; second, the type of config should be changed from {} to any and the unnecessary non-null assertion on callback should be removed to improve type safety.
ccbc15d to
a2df4f2
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the Snapshot class in transaction.ts by extracting the logic for binding the multiplexed session affinity key to gaxOpts into a private helper method _applyAffinityGaxOpts. It also adds corresponding unit tests to verify that detached requests function correctly and that caller-supplied options are not mutated. However, in the refactoring, the callback parameter of this.request was incorrectly changed from optional to required, which could break TypeScript compilation for callers expecting a Promise; this should be reverted to optional.
Snapshot#request and Snapshot#requestStream each contained their own copy of the same logic for adding the multiplexed session affinity key to the gax options of a request. Both now call a single private helper. The helper assigns the affinity key to the request descriptor instead of copying it first. That descriptor is built by the caller for one specific RPC, and prepareGapicRequest_ already modifies it in place, so the copy served no purpose. It removes one object allocation per request. The caller's own gax options are still never modified.
a2df4f2 to
7bdeff8
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the Snapshot class in transaction.ts by extracting the multiplexed session affinity key binding logic into a new private helper method _applyAffinityGaxOpts, and adds corresponding unit tests to verify its behavior and ensure request and requestStream remain usable when detached. Feedback was provided regarding the potential side effects of mutating the user-supplied config object directly in _applyAffinityGaxOpts, suggesting the use of a deep copy instead.
Snapshot#request and Snapshot#requestStream each contained their own copy of the same logic for adding the multiplexed session affinity key to the gax options of a request. Both now call a single private helper.
The helper assigns the affinity key to the request descriptor instead of copying it first. That descriptor is built by the caller for one specific RPC, and prepareGapicRequest_ already modifies it in place, so the copy served no purpose. It removes one object allocation per request. The caller's own gax options are still never modified.