Skip to content

Commit e8f419b

Browse files
Migrate FieldValue to Protobuf (#8124)
1 parent 04ab074 commit e8f419b

File tree

196 files changed

+6609
-6924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+6609
-6924
lines changed

FirebaseFirestore.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
9090
abseil_version = '0.20200225.0'
9191
s.dependency 'abseil/algorithm', abseil_version
9292
s.dependency 'abseil/base', abseil_version
93+
s.dependency 'abseil/container/flat_hash_map', abseil_version
9394
s.dependency 'abseil/memory', abseil_version
9495
s.dependency 'abseil/meta', abseil_version
9596
s.dependency 'abseil/strings/strings', abseil_version

Firestore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [changed] Internal refactor to improve serialization performance.
3+
14
# v8.4.0
25
- [fixed] Fixed handling of Unicode characters in log and assertion messages
36
(#8372).

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
using firebase::firestore::model::DocumentComparator;
5050
using firebase::firestore::model::DocumentKeySet;
5151
using firebase::firestore::model::DocumentSet;
52-
using firebase::firestore::model::DocumentState;
5352

5453
using testutil::Doc;
5554
using testutil::DocSet;
@@ -88,8 +87,8 @@ - (void)testEquals {
8887
}
8988

9089
- (void)testIncludeMetadataChanges {
91-
Document doc1Old = Doc("foo/bar", 1, Map("a", "b"), DocumentState::kLocalMutations);
92-
Document doc1New = Doc("foo/bar", 1, Map("a", "b"), DocumentState::kSynced);
90+
Document doc1Old = Doc("foo/bar", 1, Map("a", "b")).SetHasLocalMutations();
91+
Document doc1New = Doc("foo/bar", 1, Map("a", "b"));
9392

9493
Document doc2Old = Doc("foo/baz", 1, Map("a", "b"));
9594
Document doc2New = Doc("foo/baz", 1, Map("a", "c"));

Firestore/Example/Tests/API/FSTAPIHelpers.mm

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
#import "Firestore/Source/API/FIRFirestore+Internal.h"
3232
#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
3333
#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
34-
#import "Firestore/Source/API/FSTUserDataConverter.h"
34+
#import "Firestore/Source/API/FSTUserDataReader.h"
3535

3636
#include "Firestore/core/src/core/view_snapshot.h"
3737
#include "Firestore/core/src/model/document.h"
3838
#include "Firestore/core/src/model/document_set.h"
39+
#include "Firestore/core/src/model/mutable_document.h"
40+
#include "Firestore/core/src/nanopb/message.h"
3941
#include "Firestore/core/src/remote/firebase_metadata_provider.h"
4042
#include "Firestore/core/src/util/string_apple.h"
4143
#include "Firestore/core/test/unit/testutil/testutil.h"
@@ -45,13 +47,14 @@
4547
using firebase::firestore::api::SnapshotMetadata;
4648
using firebase::firestore::core::DocumentViewChange;
4749
using firebase::firestore::core::ViewSnapshot;
50+
using firebase::firestore::google_firestore_v1_Value;
4851
using firebase::firestore::model::DatabaseId;
4952
using firebase::firestore::model::Document;
5053
using firebase::firestore::model::DocumentComparator;
5154
using firebase::firestore::model::DocumentKeySet;
5255
using firebase::firestore::model::DocumentSet;
53-
using firebase::firestore::model::DocumentState;
54-
using firebase::firestore::model::FieldValue;
56+
using firebase::firestore::model::MutableDocument;
57+
using firebase::firestore::nanopb::Message;
5558

5659
using testutil::Doc;
5760
using testutil::Query;
@@ -82,15 +85,15 @@
8285
NSDictionary<NSString *, id> *_Nullable data,
8386
BOOL hasMutations,
8487
BOOL fromCache) {
85-
absl::optional<Document> doc;
88+
absl::optional<MutableDocument> doc;
8689
if (data) {
87-
FSTUserDataConverter *converter = FSTTestUserDataConverter();
88-
FieldValue parsed = [converter parsedQueryValue:data];
90+
FSTUserDataReader *reader = FSTTestUserDataReader();
91+
Message<google_firestore_v1_Value> parsed = [reader parsedQueryValue:data];
8992

90-
doc = Doc(path, version, parsed,
91-
hasMutations ? DocumentState::kLocalMutations : DocumentState::kSynced);
93+
doc = Doc(path, version, std::move(parsed));
94+
if (hasMutations) doc->SetHasLocalMutations();
9295
}
93-
return [[FIRDocumentSnapshot alloc] initWithFirestore:FSTTestFirestore().wrapped
96+
return [[FIRDocumentSnapshot alloc] initWithFirestore:FSTTestFirestore()
9497
documentKey:testutil::Key(path)
9598
document:doc
9699
fromCache:fromCache
@@ -114,35 +117,34 @@
114117
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
115118
BOOL hasPendingWrites,
116119
BOOL fromCache) {
117-
FSTUserDataConverter *converter = FSTTestUserDataConverter();
120+
FSTUserDataReader *reader = FSTTestUserDataReader();
118121

119122
SnapshotMetadata metadata(hasPendingWrites, fromCache);
120123
DocumentSet oldDocuments(DocumentComparator::ByKey());
121124
DocumentKeySet mutatedKeys;
122125
for (NSString *key in oldDocs) {
123-
FieldValue doc = [converter parsedQueryValue:oldDocs[key]];
126+
Message<google_firestore_v1_Value> value = [reader parsedQueryValue:oldDocs[key]];
124127
std::string documentKey = util::StringFormat("%s/%s", path, key);
125-
oldDocuments = oldDocuments.insert(
126-
Doc(documentKey, 1, doc,
127-
hasPendingWrites ? DocumentState::kLocalMutations : DocumentState::kSynced));
128+
MutableDocument doc = Doc(documentKey, 1, std::move(value));
128129
if (hasPendingWrites) {
129130
mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
131+
doc.SetHasLocalMutations();
130132
}
133+
oldDocuments = oldDocuments.insert(doc);
131134
}
132135

133136
DocumentSet newDocuments = oldDocuments;
134137
std::vector<DocumentViewChange> documentChanges;
135138
for (NSString *key in docsToAdd) {
136-
FieldValue doc = [converter parsedQueryValue:docsToAdd[key]];
139+
Message<google_firestore_v1_Value> value = [reader parsedQueryValue:docsToAdd[key]];
137140
std::string documentKey = util::StringFormat("%s/%s", path, key);
138-
Document docToAdd =
139-
Doc(documentKey, 1, doc,
140-
hasPendingWrites ? DocumentState::kLocalMutations : DocumentState::kSynced);
141-
newDocuments = newDocuments.insert(docToAdd);
142-
documentChanges.emplace_back(docToAdd, DocumentViewChange::Type::Added);
141+
MutableDocument doc = Doc(documentKey, 1, std::move(value));
142+
documentChanges.emplace_back(doc, DocumentViewChange::Type::Added);
143143
if (hasPendingWrites) {
144144
mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
145+
doc.SetHasLocalMutations();
145146
}
147+
newDocuments = newDocuments.insert(doc);
146148
}
147149
ViewSnapshot viewSnapshot{Query(path),
148150
newDocuments,

0 commit comments

Comments
 (0)