Skip to content
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

Do not consider MutableDocument's state for DocumentSnapshot comparison #8647

Merged
merged 5 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# v8.6.0
- [changed] Internal refactor to improve serialization performance.
- [changed] `DocumentSnapshot` objects consider the document's key and data for
equality comparison, but ignore the internal state and internal version.

# v8.4.0
- [fixed] Fixed handling of Unicode characters in log and assertion messages
Expand Down
30 changes: 30 additions & 0 deletions Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ - (void)testCanUpdateAnExistingDocument {
XCTAssertEqualObjects(result.data, finalData);
}

- (void)testEqualityComparison {
FIRDocumentReference *doc = [self.db documentWithPath:@"rooms/eros"];
NSDictionary<NSString *, id> *initialData =
@{@"desc" : @"Description", @"owner" : @{@"name" : @"Jonny", @"email" : @"[email protected]"}};

[self writeDocumentRef:doc data:initialData];

FIRDocumentSnapshot *snap1 = [self readDocumentForRef:doc];
FIRDocumentSnapshot *snap2 = [self readDocumentForRef:doc];
FIRDocumentSnapshot *snap3 = [self readDocumentForRef:doc];

XCTAssertTrue([snap1.metadata isEqual:snap2.metadata]);
XCTAssertTrue([snap2.metadata isEqual:snap3.metadata]);

XCTAssertTrue([snap1.documentID isEqual:snap2.documentID]);
XCTAssertTrue([snap2.documentID isEqual:snap3.documentID]);

XCTAssertTrue(snap1.exists == snap2.exists);
XCTAssertTrue(snap2.exists == snap3.exists);

XCTAssertTrue([snap1.reference isEqual:snap2.reference]);
XCTAssertTrue([snap2.reference isEqual:snap3.reference]);

XCTAssertTrue([[snap1 data] isEqual:[snap2 data]]);
XCTAssertTrue([[snap2 data] isEqual:[snap3 data]]);

XCTAssertTrue([snap1 isEqual:snap2]);
XCTAssertTrue([snap2 isEqual:snap3]);
}

- (void)testCanUpdateAnUnknownDocument {
[self readerAndWriterOnDocumentRef:^(FIRDocumentReference *readerRef,
FIRDocumentReference *writerRef) {
Expand Down
5 changes: 4 additions & 1 deletion Firestore/core/src/api/document_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ absl::optional<google_firestore_v1_Value> DocumentSnapshot::GetValue(
bool operator==(const DocumentSnapshot& lhs, const DocumentSnapshot& rhs) {
return lhs.firestore_ == rhs.firestore_ &&
lhs.internal_key_ == rhs.internal_key_ &&
lhs.internal_document_ == rhs.internal_document_ &&
lhs.exists() == rhs.exists() &&
(lhs.exists() ? lhs.internal_document_->get().data() ==
rhs.internal_document_->get().data()
: true) &&
lhs.metadata_ == rhs.metadata_;
}

Expand Down
2 changes: 1 addition & 1 deletion Firestore/core/src/model/mutable_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class MutableDocument {
return value_->Get();
}

ObjectValue& data() {
ObjectValue& data() const {
return *value_;
}

Expand Down