-
Notifications
You must be signed in to change notification settings - Fork 928
Replace usage of transform with updateTransforms #4153
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/firestore': minor | ||
--- | ||
|
||
Field tranforms performed within a write no longer count as additional operations. However, a field transform on its own still counts as an operation. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,30 @@ export function fromDbMutationBatch( | |
const baseMutations = (dbBatch.baseMutations || []).map(m => | ||
fromMutation(localSerializer.remoteSerializer, m) | ||
); | ||
|
||
// Squash old transform mutations into existing patch or set mutations. | ||
// The replacement of representing `transforms` with `update_transforms` | ||
// on the SDK means that old `transform` mutations stored in IndexedDB need | ||
// to be updated to `update_transforms`. | ||
// TODO(b/174608374): Remove this code once we perform a schema migration. | ||
let i = dbBatch.mutations.length - 1; | ||
while (i >= 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be easier to parse as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
const mutationProto = dbBatch.mutations[i]; | ||
if (mutationProto?.transform !== undefined) { | ||
debugAssert( | ||
i >= 1 && | ||
dbBatch.mutations[i - 1].transform === undefined && | ||
dbBatch.mutations[i - 1].update !== undefined, | ||
'TransformMutation should be preceded by a patch or set mutation' | ||
); | ||
const mutationToJoin = dbBatch.mutations[i - 1]; | ||
mutationToJoin.updateTransforms = mutationProto.transform.fieldTransforms; | ||
dbBatch.mutations.splice(i, 1); | ||
--i; | ||
} | ||
--i; | ||
} | ||
|
||
const mutations = dbBatch.mutations.map(m => | ||
fromMutation(localSerializer.remoteSerializer, m) | ||
); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FieldTransform
is not a concept we expose to users. How about:"A write to a document that contains FieldValue sentinels is no longer split up into two separate operations. This reduces the number of writes the backend performs"
We could maybe also mention how this affects WriteBatch.
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.
The reference docs refer to transforms as: "Within a write operation, field transforms like ... each count as an additional operation" (link). I also wanted to clarify that multiple field transforms also count as a single write. Changed to reflect your wording.
I did consider mentioning how this might affect WriteBatch's 500-write limit, but then I realized that considering we're doing all this work with BulkWriter to mitigate backend pressure from big batches, why encourage bigger batches to begin with? WDYT?
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.
Most users access Firestore through our SDK. They are not aware of the terminology that is used in the Proto, and we should use the SDK terms in our release notes (at least in addition to the Proto terms).
BulkWriter will not come to the Mobile SDKs. WriteBatches on Mobile are meant for atomic commits and I don't expect that people will use them for large bulk insertions.
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.
Thanks for explaining. I changed it to use your wording and added a bit about WriteBatch limits.