Skip to content

Store the coerced base value in the BaseMutation #1928

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 5 commits into from
Jul 3, 2019

Conversation

schmidt-sebastian
Copy link
Contributor

Port of firebase/firebase-android-sdk#564

The PR changes what we store in a BaseMutation. With the changes here, every transform operation computes what it needs to store in the BaseMutation. For Numeric increment, this is either an existing numeric value or the IntegerValue.of(0), replacing all invalid base values at time of creation.

@schmidt-sebastian schmidt-sebastian requested a review from a user June 28, 2019 21:10
@@ -605,6 +606,31 @@ export class ObjectValue extends FieldValue {
return field;
}

/** Recursively extracts the FieldPaths that are set in this ObjectValue. */
Copy link

Choose a reason for hiding this comment

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

I feel like the comments here can be elaborated, something like:

Returns a FieldMask built from all FieldPaths starting from this ObjectValue, including paths from nested objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (went with your version).

* applied. Mutations that replace the entire document return 'null'.
* If applicable, returns the base value to persist with this mutation. If a
* base value is provided, the mutation is always applied to this base value,
* even if document has already beenupdated.
Copy link

Choose a reason for hiding this comment

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

beenupdated -> been updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

* If applicable, returns the field mask for this mutation. Fields that are
* not included in this field mask are not modified when this mutation is
* applied. Mutations that replace the entire document return 'null'.
* If applicable, returns the base value to persist with this mutation. If a
Copy link

Choose a reason for hiding this comment

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

When is this not applicable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with "If this mutation is not idempotent"

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Mostly requesting for comments changes and renames.

I do have a question that does not seem obvious from reading the code around non-idempotent mutations (not particularly related to this change): if two users apply to increment to the same field, one of them has to apply it to the other's result and therefore ignoring the base value for its own mutation, is that a good guess on what the expected behavior is?

@ghost ghost assigned schmidt-sebastian and unassigned ghost Jul 2, 2019
@schmidt-sebastian
Copy link
Contributor Author

Adding @wilhuff for Owners approval.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM with comment nits

// The following update includes an update of the nested map "deep", which
// updates it to contain a single ServerTimestamp. As such, the update is
// split into two mutations: One that sets "deep" to an empty map and
// overwrites the previous ServerTimestamp value and a second ransform that
Copy link
Contributor

Choose a reason for hiding this comment

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

s/ransform/transform/

@@ -209,6 +209,14 @@ apiDescribe('Server Timestamps', (persistence: boolean) => {
});

it('can return previous value', () => {
// The following update includes an update of the nested map "deep", which
Copy link
Contributor

Choose a reason for hiding this comment

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

"The following update includes an update" sounds wrong. Maybe you meant "The following test includes an update"?

Also "As such" doesn't work here. I think what you're trying to say is that the implementation of the update call is to split it into two mutations ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed "as such" and replaced with "This update".

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Jul 2, 2019
@schmidt-sebastian schmidt-sebastian merged commit f2f6eef into master Jul 3, 2019
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/basevalues branch July 3, 2019 15:45
@firebase firebase locked and limited conversation to collaborators Oct 10, 2019
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.

2 participants