-
Notifications
You must be signed in to change notification settings - Fork 615
Replace usage of transform with updateTransforms #2262
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
Conversation
ad6ddee
to
283773f
Compare
Coverage ReportAffected SDKs
Test Logs
NotesHTML coverage reports can be produced locally with Head commit (bc50b600) is created by Prow via merging commits: ee74cd0 8c1b565. |
Binary Size ReportAffected SDKs
Test Logs
NotesHead commit (bc50b600) is created by Prow via merging commits: ee74cd0 8c1b565. |
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.
Very nice!
&& batch.getWrites(i - 1).getTransform().getFieldTransformsCount() == 0 | ||
&& batch.getWrites(i - 1).getUpdate().getFieldsCount() != 0, |
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.
&& batch.getWrites(i - 1).getTransform().getFieldTransformsCount() == 0 | |
&& batch.getWrites(i - 1).getUpdate().getFieldsCount() != 0, | |
&& !batch.getWrites(i - 1).hasTransform() | |
&& batch.getWrites(i - 1).hasUpdate(), |
Proto3 does have "has" functions for nested messages.
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.
Done.
.removeWrites(i) | ||
.removeWrites(i - 1) | ||
.addWrites(i - 1, newMutationBuilder.build()) | ||
.build(); |
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.
Can you change this so it only runs once per batch?
* if the prior mutation resulted in a Document (always true for a SetMutation, but not necessarily | ||
* for an PatchMutation). | ||
* <p>Field transforms are used only with Patch and Set Mutations. We use the `updateTransforms` | ||
* field to store transforms, rather than the `transforms` field. |
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.
Nit: "transforms
field" might be a bit misleading. Maybe rephrase as "rather than sending an additional transforms
message"
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.
done.
@@ -129,7 +138,9 @@ public abstract MaybeDocument applyToLocalView( | |||
* @return a base value to store along with the mutation, or null for idempotent mutations. | |||
*/ | |||
@Nullable | |||
public abstract ObjectValue extractBaseValue(@Nullable MaybeDocument maybeDoc); | |||
public ObjectValue extractBaseValue(@Nullable MaybeDocument maybeDoc) { | |||
return extractTransformBaseValue(maybeDoc); |
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.
It looks like we can just inline this call. The Web SDK is slightly different to support tree-shaking.
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.
done.
firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Mutation.java
Outdated
Show resolved
Hide resolved
--i; | ||
} | ||
} | ||
|
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.
Another idea would be to simply build up a new list of Mutations, which we can then iterate in the three lines below. That would avoid all toBuilder() conversions.
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.
Done. Used a builder to accumulate everything before building at the end of the loop
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.
It looks like prepending an element to a list in Protobuf is an O(n) operation. Would it be possible to reverse this loop so we can append at the end? We could also just scrap the Builder entirely and just build up mutations
directly (see the 5 lines below).
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.
ended up using mutations directly.
@@ -59,13 +67,204 @@ | |||
private RemoteSerializer remoteSerializer; | |||
private LocalSerializer serializer; | |||
|
|||
private Timestamp writeTime = Timestamp.now(); | |||
com.google.protobuf.Timestamp writeTimeProto = |
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.
Should this be private as well>
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.
done.
.setNanos(writeTime.getNanoseconds()) | ||
.build(); | ||
|
||
static class TestWriteBuilder { |
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.
Nice :)
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.
learning from the best :)
MutationBatch decoded = serializer.decodeMutationBatch(batchProto); | ||
assertEquals(1, decoded.getMutations().size()); | ||
assertTrue(decoded.getMutations().get(0) instanceof SetMutation); | ||
Write serialized = remoteSerializer.encodeMutation(decoded.getMutations().get(0)); |
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.
Maybe s/serialized/encoded ?
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.
done.
|
||
mutation = |
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.
Super optional nit (here and below): To me, set
is the base case and patch
is more advanced. I would flip the order of these assertions.
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.
done here and below
Porting from web.