-
Notifications
You must be signed in to change notification settings - Fork 587
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
Adding FieldValue.numericAdd() #105
Conversation
f3e1ff8
to
59e73c2
Compare
0d26c0e
to
1ca97b4
Compare
Hm, looks like this broke |
1ca97b4
to
6eadd27
Compare
I reverted the change that simplified the plumbing as this broke updates for transforms that were nested inside of a map. |
6eadd27
to
acd83e1
Compare
acd83e1
to
20152fe
Compare
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.
On the whole, this looks fantastic. The baseMutations approach made this much less disruptive than I expected. Nice work! I have one potential concern about merge-set behavior, but we can perhaps punt on that. Otherwise, just lots of minor nits.
...base-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java
Outdated
Show resolved
Hide resolved
firebase-firestore/src/proto/google/firebase/firestore/proto/mutation.proto
Outdated
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/FieldValue.java
Outdated
Show resolved
Hide resolved
...base-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java
Show resolved
Hide resolved
...base-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java
Outdated
Show resolved
Hide resolved
...base-firestore/src/androidTest/java/com/google/firebase/firestore/NumericTransformsTest.java
Show resolved
Hide resolved
...base-firestore/src/androidTest/java/com/google/firebase/firestore/NumericTransformsTest.java
Show resolved
Hide resolved
firebase-firestore/src/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java
Show resolved
Hide resolved
firebase-firestore/src/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java
Show resolved
Hide resolved
firebase-firestore/src/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java
Outdated
Show resolved
Hide resolved
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.
Addressed most feedback. Feel free to push back on some of my decisions :)
...base-firestore/src/androidTest/java/com/google/firebase/firestore/NumericTransformsTest.java
Outdated
Show resolved
Hide resolved
...base-firestore/src/androidTest/java/com/google/firebase/firestore/NumericTransformsTest.java
Show resolved
Hide resolved
...base-firestore/src/androidTest/java/com/google/firebase/firestore/NumericTransformsTest.java
Show resolved
Hide resolved
...restore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/FieldValue.java
Outdated
Show resolved
Hide resolved
firebase-firestore/src/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/local/MutationQueue.java
Show resolved
Hide resolved
...base-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java
Show resolved
Hide resolved
...base-firestore/src/main/java/com/google/firebase/firestore/model/mutation/MutationBatch.java
Outdated
Show resolved
Hide resolved
...restore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java
Outdated
Show resolved
Hide resolved
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! Mild pushback / clarification on a couple things.
* @return The mutations that are used to populate the base values when this mutation batch is | ||
* applied locally. | ||
*/ | ||
public List<Mutation> getBaseMutations() { |
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.
"There may be more suitable use cases for this in the future, in which case the more general name may make more sense." Can you provide an example of such a use case?
Offhand I strongly suspect this will never be used for anything else, and so I'd err towards present naming clarity rather than futureproof-ing the name. I can be convinced otherwise though.
...-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformMutation.java
Show resolved
Hide resolved
...restore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java
Outdated
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java
Outdated
Show resolved
Hide resolved
// Note: Theoretically, we should only include non-idempotent fields in this field mask as this | ||
// mask is used to populate the base state for all DocumentTransforms. By including all | ||
// fields, we incorrectly prevent rebasing of idempotent transforms (such as `arrayUnion()`) | ||
// when any non-idempotent transforms are present. |
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.
This is a good comment, but it may not make sense out-of-context (it assumes knowledge of how this method is going to be used). I'd actually move it into LocalStore where getFieldMask() is called rather than having it here.
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.
Yeah, that makes sense. It's basically the same reason as to why I don't want to exclude the idempotent fields here.
@@ -968,6 +968,9 @@ public void testHandlesSetMutationThenTransformMutationThenTransformMutation() { | |||
@Test | |||
public void testHandlesSetMutationThenAckThenTransformMutationThenAckThenTransformMutation() { | |||
if (garbageCollectorIsEager()) { | |||
// Since this test doesn't open a Query, Eager GC removes the documents from the cache as soon |
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.
"open a Query" => "start a listen" ?
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/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java
Show resolved
Hide resolved
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.
Oh... nice.
* @return The mutations that are used to populate the base values when this mutation batch is | ||
* applied locally. | ||
*/ | ||
public List<Mutation> getBaseMutations() { |
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.
Oh... nice.
assertNotContains("foo/bar"); | ||
|
||
applyRemoteEvent(addedRemoteEvent(doc("foo/bar", 1, map("sum", 1337)), asList(2), emptyList())); | ||
assertChanged(doc("foo/bar", 1, map("sum", 1), Document.DocumentState.LOCAL_MUTATIONS)); |
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.
Oh... nice.
mutation.getKey(), | ||
ObjectValue.emptyObject(), | ||
fieldMask, | ||
mutation.getPrecondition())); |
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.
Oh... 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.
proto changes: oh... 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.
LGTM
FYI: Pushed commit to rename this to "increment" as per the API Council. |
c7e8172
to
991fb7c
Compare
@schmidt-sebastian: The following tests failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@schmidt-sebastian: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@schmidt-sebastian: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
This PR adds support for the Numeric Add transform and follows the semantics of the backend implementation. To avoid flicker with latency compensation, it adds the concept of "base values", which are stored as a list of patch mutations along with the transform mutations in a mutation batch. The base mutations are applied first and are used to overwrite values from the remote document cache.
This PR also simplifies some plumbing in regards to the "previous value", which is used when rendering Server Timestamps. Before, if two server timestamps replaced the same value in sequence, each timestamp would point to this previous value. Now, the previous value is chained, and the second timestamp obtains its previous value by asking the first timestamp for its previous value. This is slightly less optimal, but simplifies the changes that this PR introduces to Local Store.As an additional benefit, and to get this PR passed 1000 lines of code, I added a flag to run the Integration Tests against Hexa. Because I don't know how to add custom configurations in gradle, this is for now hardcoded.