Skip to content

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

Merged
merged 4 commits into from
Dec 17, 2020

Conversation

thebrianchen
Copy link

Porting from web.

@thebrianchen thebrianchen self-assigned this Dec 16, 2020
@google-cla google-cla bot added the cla: yes Override cla label Dec 16, 2020
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 16, 2020

Coverage Report

Affected SDKs

  • firebase-firestore

    SDK overall coverage changed from 46.63% (ee74cd0) to 46.78% (bc50b600) by +0.14%.

    Click to show coverage changes in 12 files.
    Filename Base (ee74cd0) Head (bc50b600) Diff
    DeleteMutation.java 84.21% 83.33% -0.88%
    DocumentTransform.java 29.66% 29.44% -0.22%
    GrpcCallProvider.java 68.18% 57.95% -10.23%
    LocalSerializer.java 96.97% 97.30% +0.33%
    Mutation.java 93.75% 98.41% +4.66%
    PatchMutation.java 91.11% 92.31% +1.20%
    RemoteSerializer.java 83.68% 83.29% -0.39%
    SetMutation.java 80.00% 84.85% +4.85%
    UserData.java 54.37% 66.00% +11.63%
    UserDataReader.java 65.71% 70.48% +4.76%
    VerifyMutation.java 46.15% 50.00% +3.85%
    Write.java 30.63% 36.25% +5.62%

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (bc50b600) is created by Prow via merging commits: ee74cd0 8c1b565.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 16, 2020

Binary Size Report

Affected SDKs

  • firebase-firestore

    Type Base (ee74cd0) Head (bc50b600) Diff
    aar 1.00 MB 1.00 MB -1.70 kB (-0.2%)
    apk (release) 3.15 MB 3.15 MB -304 B (-0.0%)

Test Logs

Notes

Head commit (bc50b600) is created by Prow via merging commits: ee74cd0 8c1b565.

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.

Very nice!

Comment on lines 187 to 188
&& batch.getWrites(i - 1).getTransform().getFieldTransformsCount() == 0
&& batch.getWrites(i - 1).getUpdate().getFieldsCount() != 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
&& 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.

Copy link
Author

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();
Copy link
Contributor

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.
Copy link
Contributor

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"

Copy link
Author

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);
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

done.

--i;
}
}

Copy link
Contributor

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.

Copy link
Author

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

Copy link
Contributor

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).

Copy link
Author

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 =
Copy link
Contributor

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>

Copy link
Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice :)

Copy link
Author

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));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe s/serialized/encoded ?

Copy link
Author

Choose a reason for hiding this comment

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

done.


mutation =
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

done here and below

@thebrianchen thebrianchen removed their assignment Dec 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants