Skip to content

UserDataReader #7843

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 14 commits into from
Apr 12, 2021
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Apr 5, 2021

Note: This PR is much smaller than it appears.

This adds Android's UserDataReader, which is basically UserDataConverter but instead of converting user data to FieldValues, it directly converts user data to Proto. To make this less intrusive, UserDataReader currently uses UserDataConverter to then convert the Protos to FieldValues (this step will be removed soon).

To make the diff easier to review, UserDataConverter is renamed to UserDataConverter_legacy and a bunch of comment changes have been made to force Git to show the diff between UserDataReader and UserDataConverter (rather than from UserDataConverter to UserDataConverter_legacy).

@google-cla google-cla bot added the cla: yes label Apr 5, 2021
@google-oss-bot
Copy link

1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger

@google-oss-bot
Copy link

google-oss-bot commented Apr 6, 2021

Coverage Report

Affected SDKs

  • FirebaseFirestore-iOS-FirebaseFirestore.framework

    SDK overall coverage changed from 88.51% (6eaf761) to 86.91% (7f11826) by -1.59%.

    Click to show coverage changes in 11 files.
    Filename Base (6eaf761) Head (7f11826) Diff
    FIRDocumentSnapshot.mm 89.84% 89.89% +0.05%
    FIRFirestore.mm 91.63% 91.61% -0.02%
    FSTUserDataConverter_legacy.mm ? 0.00% ?
    FSTUserDataReader.mm ? 95.88% ?
    leveldb_key.cc 97.52% 97.96% +0.44%
    leveldb_migrations.cc 100.00% 93.40% -6.60%
    mutable_document.cc ? 0.00% ?
    object_value.cc ? 98.81% ?
    serializer.cc 83.96% 84.53% +0.57%
    server_timestamp_util.cc ? 84.85% ?
    value_util.cc ? 88.50% ?

Test Logs

input = self.preConverter(input);
if ([input isKindOfClass:[NSDictionary class]]) {
return [self parseDictionary:(NSDictionary *)input context:std::move(context)];
return absl::optional<google_firestore_v1_Value>{[self parseDictionary:(NSDictionary *)input
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you should be able to just return [self parseDictionary] (the way it was done before) -- an optional can be implicitly created from the value (here and below).

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 here and everywhere. It shows up as a compile error in CLion, but the build passes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, what is the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returning google_firestore_v1_Value from a method returning absl::optional<google_firestore_v1_Value>: Class google_firestore_v1_Value is not compatible with absl::optional<google_firestore_v1_Value>

[dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *) {
absl::optional<FieldValue> parsedValue =
absl::optional<google_firestore_v1_Value> parsedValue =
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: what does it take to know whether the value can be parsed? What I'm getting at is whether it could be feasible to do a first pass on dict to get the array size, then create the values right in the array and skip the vector.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to check whether it is a FIeldValue sentinel, which would duplicate the existing check in parseData. I don't think we can remove the parseData check since this function has more than this callsite.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, if I'm reading the code correctly, it amounts to going through the dictionary and calling [input isKindOfClass:[FIRFieldValue class]] on each element. If this is correct, then I strongly suspect that it's faster than creating and filling a vector and then copying vector elements into the array. What do you think about doing this, perhaps in a follow-up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this in this PR.

* Transfer master branch testing podspec repo to open source.

* Update the tool to only remove dirs and retain CONTRIBUTION, LICENSE and README.md.
Copy link
Contributor

@var-const var-const left a comment

Choose a reason for hiding this comment

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

Pretty much LGTM with one question.

input = self.preConverter(input);
if ([input isKindOfClass:[NSDictionary class]]) {
return [self parseDictionary:(NSDictionary *)input context:std::move(context)];
return absl::optional<google_firestore_v1_Value>{[self parseDictionary:(NSDictionary *)input
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, what is the error?

[dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *) {
absl::optional<FieldValue> parsedValue =
absl::optional<google_firestore_v1_Value> parsedValue =
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, if I'm reading the code correctly, it amounts to going through the dictionary and calling [input isKindOfClass:[FIRFieldValue class]] on each element. If this is correct, then I strongly suspect that it's faster than creating and filling a vector and then copying vector elements into the array. What do you think about doing this, perhaps in a follow-up?

@schmidt-sebastian schmidt-sebastian merged commit 38cefe1 into mrschmidt/mutabledocuments Apr 12, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/userdatareader branch April 12, 2021 18:25
@firebase firebase locked and limited conversation to collaborators May 13, 2021
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.

5 participants