Skip to content

Port DocumentState and UnknownDocument. #2160

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 3 commits into from
Dec 19, 2018
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
28 changes: 11 additions & 17 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@
AB380D04201BC6E400D97691 /* ordered_code_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380D03201BC6E400D97691 /* ordered_code_test.cc */; };
AB38D93020236E21000A432D /* database_info_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB38D92E20235D22000A432D /* database_info_test.cc */; };
AB6B908420322E4D00CC290A /* document_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB6B908320322E4D00CC290A /* document_test.cc */; };
AB6B908620322E6D00CC290A /* maybe_document_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB6B908520322E6D00CC290A /* maybe_document_test.cc */; };
AB6B908820322E8800CC290A /* no_document_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB6B908720322E8800CC290A /* no_document_test.cc */; };
AB7BAB342012B519001E0872 /* geo_point_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB7BAB332012B519001E0872 /* geo_point_test.cc */; };
ABA495BB202B7E80008A7851 /* snapshot_version_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABA495B9202B7E79008A7851 /* snapshot_version_test.cc */; };
Expand All @@ -203,7 +202,6 @@
B65D34A9203C995B0076A5E1 /* FIRTimestampTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B65D34A7203C99090076A5E1 /* FIRTimestampTest.m */; };
B66D8996213609EE0086DA0C /* stream_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = B66D8995213609EE0086DA0C /* stream_test.mm */; };
B67BF449216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */; };
B67BF44A216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */; };
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2AD2023DDB20028D6BE /* field_path_test.cc */; };
B686F2B22025000D0028D6BE /* resource_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2B02024FFD70028D6BE /* resource_path_test.cc */; };
B6BBE43121262CF400C6A53E /* grpc_stream_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6BBE42F21262CF400C6A53E /* grpc_stream_test.cc */; };
Expand Down Expand Up @@ -505,7 +503,6 @@
AB38D9342023966E000A432D /* credentials_provider_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = credentials_provider_test.cc; sourceTree = "<group>"; };
AB38D93620239689000A432D /* empty_credentials_provider_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = empty_credentials_provider_test.cc; sourceTree = "<group>"; };
AB6B908320322E4D00CC290A /* document_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = document_test.cc; sourceTree = "<group>"; };
AB6B908520322E6D00CC290A /* maybe_document_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = maybe_document_test.cc; sourceTree = "<group>"; };
AB6B908720322E8800CC290A /* no_document_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = no_document_test.cc; sourceTree = "<group>"; };
AB71064B201FA60300344F18 /* database_id_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = database_id_test.cc; sourceTree = "<group>"; };
AB7BAB332012B519001E0872 /* geo_point_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = geo_point_test.cc; sourceTree = "<group>"; };
Expand Down Expand Up @@ -665,12 +662,12 @@
546854A720A3681B004BDBD5 /* remote */ = {
isa = PBXGroup;
children = (
B6D964942163E63900EB9CFB /* grpc_unary_call_test.cc */,
B6D9649021544D4F00EB9CFB /* grpc_connection_test.cc */,
B6D964922154AB8F00EB9CFB /* grpc_streaming_reader_test.cc */,
546854A820A36867004BDBD5 /* datastore_test.mm */,
B6D1B68420E2AB1A00B35856 /* exponential_backoff_test.cc */,
B6D9649021544D4F00EB9CFB /* grpc_connection_test.cc */,
B6BBE42F21262CF400C6A53E /* grpc_stream_test.cc */,
B6D964922154AB8F00EB9CFB /* grpc_streaming_reader_test.cc */,
B6D964942163E63900EB9CFB /* grpc_unary_call_test.cc */,
61F72C5520BC48FD001A68CB /* serializer_test.cc */,
B66D8995213609EE0086DA0C /* stream_test.mm */,
);
Expand All @@ -680,10 +677,6 @@
54740A561FC913EB00713A1A /* util */ = {
isa = PBXGroup;
children = (
B60894F62170207100EBC644 /* fake_credentials_provider.cc */,
B60894F52170207100EBC644 /* fake_credentials_provider.h */,
B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */,
B67BF447216EB42F00CA9097 /* create_noop_connectivity_monitor.h */,
B6FB4680208EA0BE00554BA2 /* async_queue_libdispatch_test.mm */,
B6FB4681208EA0BE00554BA2 /* async_queue_std_test.cc */,
B6FB467B208E9A8200554BA2 /* async_queue_test.cc */,
Expand All @@ -692,10 +685,14 @@
54740A521FC913E500713A1A /* autoid_test.cc */,
AB380D01201BC69F00D97691 /* bits_test.cc */,
548DB928200D59F600E00ABC /* comparison_test.cc */,
B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */,
B67BF447216EB42F00CA9097 /* create_noop_connectivity_monitor.h */,
B6FB4689208F9B9100554BA2 /* executor_libdispatch_test.mm */,
B6FB4687208F9B9100554BA2 /* executor_std_test.cc */,
B6FB4688208F9B9100554BA2 /* executor_test.cc */,
B6FB468A208F9B9100554BA2 /* executor_test.h */,
B60894F62170207100EBC644 /* fake_credentials_provider.cc */,
B60894F52170207100EBC644 /* fake_credentials_provider.h */,
F51859B394D01C0C507282F1 /* filesystem_test.cc */,
B1A7E1959AF8141FA7E6B888 /* grpc_stream_tester.cc */,
ED4B3E3EA0EBF3ED19A07060 /* grpc_stream_tester.h */,
Expand Down Expand Up @@ -1044,7 +1041,6 @@
549CCA5320A36E1F00BCEB75 /* field_mask_test.cc */,
B686F2AD2023DDB20028D6BE /* field_path_test.cc */,
AB356EF6200EA5EB0089B766 /* field_value_test.cc */,
AB6B908520322E6D00CC290A /* maybe_document_test.cc */,
C8522DE226C467C54E6788D8 /* mutation_test.cc */,
AB6B908720322E8800CC290A /* no_document_test.cc */,
549CCA5520A36E1F00BCEB75 /* precondition_test.cc */,
Expand Down Expand Up @@ -1870,7 +1866,6 @@
5467FB01203E5717009C9584 /* FIRFirestoreTests.mm in Sources */,
5492E052202154AB00B64F25 /* FIRGeoPointTests.mm in Sources */,
5492E059202154AB00B64F25 /* FIRQuerySnapshotTests.mm in Sources */,
B60894F72170207200EBC644 /* fake_credentials_provider.cc in Sources */,
5492E051202154AA00B64F25 /* FIRQueryTests.mm in Sources */,
5492E057202154AB00B64F25 /* FIRSnapshotMetadataTests.mm in Sources */,
B65D34A9203C995B0076A5E1 /* FIRTimestampTest.m in Sources */,
Expand Down Expand Up @@ -1905,7 +1900,6 @@
5492E0A42021552D00B64F25 /* FSTMemoryQueryCacheTests.mm in Sources */,
5492E0A52021552D00B64F25 /* FSTMemoryRemoteDocumentCacheTests.mm in Sources */,
5492E03420213FFC00B64F25 /* FSTMemorySpecTests.mm in Sources */,
B6D964952163E63900EB9CFB /* grpc_unary_call_test.cc in Sources */,
5492E03220213FFC00B64F25 /* FSTMockDatastore.mm in Sources */,
5492E0AC2021552D00B64F25 /* FSTMutationQueueTests.mm in Sources */,
5492E0BE2021555100B64F25 /* FSTMutationTests.mm in Sources */,
Expand Down Expand Up @@ -1935,6 +1929,7 @@
AB380D02201BC69F00D97691 /* bits_test.cc in Sources */,
618BBEA920B89AAC00B5BCE7 /* common.pb.cc in Sources */,
548DB929200D59F600E00ABC /* comparison_test.cc in Sources */,
B67BF449216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */,
ABC1D7DC2023A04B00BA84F0 /* credentials_provider_test.cc in Sources */,
ABE6637A201FA81900ED349A /* database_id_test.cc in Sources */,
AB38D93020236E21000A432D /* database_info_test.cc in Sources */,
Expand All @@ -1947,6 +1942,7 @@
B6FB468F208F9BAE00554BA2 /* executor_std_test.cc in Sources */,
B6FB4690208F9BB300554BA2 /* executor_test.cc in Sources */,
B6D1B68520E2AB1B00B35856 /* exponential_backoff_test.cc in Sources */,
B60894F72170207200EBC644 /* fake_credentials_provider.cc in Sources */,
549CCA5720A36E1F00BCEB75 /* field_mask_test.cc in Sources */,
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */,
54A0352620A3AED0003E0143 /* field_transform_test.mm in Sources */,
Expand All @@ -1955,9 +1951,11 @@
ABC1D7E42024AFDE00BA84F0 /* firebase_credentials_provider_test.mm in Sources */,
618BBEAA20B89AAC00B5BCE7 /* firestore.pb.cc in Sources */,
AB7BAB342012B519001E0872 /* geo_point_test.cc in Sources */,
B6D9649121544D4F00EB9CFB /* grpc_connection_test.cc in Sources */,
B6BBE43121262CF400C6A53E /* grpc_stream_test.cc in Sources */,
333FCB7BB0C9986B5DF28FC8 /* grpc_stream_tester.cc in Sources */,
B6D964932154AB8F00EB9CFB /* grpc_streaming_reader_test.cc in Sources */,
B6D964952163E63900EB9CFB /* grpc_unary_call_test.cc in Sources */,
73FE5066020EF9B2892C86BF /* hard_assert_test.cc in Sources */,
54511E8E209805F8005BD28F /* hashing_test.cc in Sources */,
618BBEB020B89AAC00B5BCE7 /* http.pb.cc in Sources */,
Expand All @@ -1968,7 +1966,6 @@
020AFD89BB40E5175838BB76 /* local_serializer_test.cc in Sources */,
54C2294F1FECABAE007D065B /* log_test.cc in Sources */,
618BBEA720B89AAC00B5BCE7 /* maybe_document.pb.cc in Sources */,
AB6B908620322E6D00CC290A /* maybe_document_test.cc in Sources */,
618BBEA820B89AAC00B5BCE7 /* mutation.pb.cc in Sources */,
32F022CB75AEE48CDDAF2982 /* mutation_test.cc in Sources */,
84DBE646DCB49305879D3500 /* nanopb_string_test.cc in Sources */,
Expand Down Expand Up @@ -2001,9 +1998,7 @@
ABC1D7E12023A40C00BA84F0 /* token_test.cc in Sources */,
54A0352720A3AED0003E0143 /* transform_operations_test.mm in Sources */,
549CCA5120A36DBC00BCEB75 /* tree_sorted_map_test.cc in Sources */,
B6D9649121544D4F00EB9CFB /* grpc_connection_test.cc in Sources */,
C80B10E79CDD7EF7843C321E /* type_traits_apple_test.mm in Sources */,
B67BF449216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */,
ABC1D7DE2023A05300BA84F0 /* user_test.cc in Sources */,
618BBEAD20B89AAC00B5BCE7 /* write.pb.cc in Sources */,
);
Expand Down Expand Up @@ -2041,7 +2036,6 @@
5492E080202154EC00B64F25 /* FSTSmokeTests.mm in Sources */,
5492E07F202154EC00B64F25 /* FSTTransactionTests.mm in Sources */,
5492E0442021457E00B64F25 /* XCTestCase+Await.mm in Sources */,
B67BF44A216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */,
EBFC611B1BF195D0EC710AF4 /* app_testing.mm in Sources */,
CA989C0E6020C372A62B7062 /* testutil.cc in Sources */,
);
Expand Down
12 changes: 10 additions & 2 deletions Firestore/core/src/firebase/firestore/local/local_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ void LocalSerializer::EncodeMaybeDocument(
});
return;

case MaybeDocument::Type::UnknownDocument:
// TODO(rsgowman): Implement
abort();

case MaybeDocument::Type::Unknown:
// TODO(rsgowman)
// TODO(rsgowman): Error handling
abort();
}

Expand Down Expand Up @@ -168,8 +172,12 @@ std::unique_ptr<NoDocument> LocalSerializer::DecodeNoDocument(
}

if (!reader->status().ok()) return nullptr;
// TODO(rsgowman): Fix hardcoding of has_committed_mutations.
// Instead, we should grab this from the proto (see other ports). However,
// we'll defer until the nanopb-master gets merged to master.
return absl::make_unique<NoDocument>(rpc_serializer_.DecodeKey(name),
*std::move(version));
*std::move(version),
/*has_committed_mutations=*/false);
}

void LocalSerializer::EncodeQueryData(Writer* writer,
Expand Down
2 changes: 2 additions & 0 deletions Firestore/core/src/firebase/firestore/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ cc_library(
snapshot_version.h
transform_operations.h
types.h
unknown_document.cc
unknown_document.h
DEPENDS
absl_optional
absl_strings
Expand Down
6 changes: 3 additions & 3 deletions Firestore/core/src/firebase/firestore/model/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace model {
Document::Document(FieldValue&& data,
DocumentKey key,
SnapshotVersion version,
bool has_local_mutations)
DocumentState document_state)
: MaybeDocument(std::move(key), std::move(version)),
data_(std::move(data)),
has_local_mutations_(has_local_mutations) {
document_state_(document_state) {
set_type(Type::Document);
HARD_ASSERT(FieldValue::Type::Object == data.type());
}
Expand All @@ -41,7 +41,7 @@ bool Document::Equals(const MaybeDocument& other) const {
}
auto& other_doc = static_cast<const Document&>(other);
return MaybeDocument::Equals(other) &&
has_local_mutations_ == other_doc.has_local_mutations_ &&
document_state_ == other_doc.document_state_ &&
data_ == other_doc.data_;
}

Expand Down
35 changes: 30 additions & 5 deletions Firestore/core/src/firebase/firestore/model/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ namespace firebase {
namespace firestore {
namespace model {

enum class DocumentState {
/**
* Local mutations applied via the mutation queue. Document is potentially
* inconsistent.
*/
kLocalMutations,

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit: maybe add a new line to visually separate the elements?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

* Mutations applied based on a write acknowledgment. Document is potentially
* inconsistent.
*/
kCommittedMutations,

/** No mutations applied. Document was sent to us by Watch. */
kSynced,
};

/**
* Represents a document in Firestore with a key, version, data and whether the
* data has local mutations applied to it.
Expand All @@ -38,7 +55,7 @@ class Document : public MaybeDocument {
Document(FieldValue&& data,
DocumentKey key,
SnapshotVersion version,
bool has_local_mutations);
DocumentState document_state);

const FieldValue& data() const {
return data_;
Expand All @@ -48,22 +65,30 @@ class Document : public MaybeDocument {
return data_.Get(path);
}

bool has_local_mutations() const {
return has_local_mutations_;
bool HasLocalMutations() const {
return document_state_ == DocumentState::kLocalMutations;
}

bool HasCommittedMutations() const {
return document_state_ == DocumentState::kCommittedMutations;
}

bool HasPendingWrites() const override {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: this function uses PascalCase, while the other two very similar functions use snake_case. Can these be in the same style? (no strong preference which)

Copy link
Member Author

Choose a reason for hiding this comment

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

http://go/c-readability-advice#virtual-accessor-names explicitly calls out this situation and suggests PascalCase for this (because it's virtual). OTOH, the style guide says that accessors "may" be snake_case. So I've switched everything to PascalCase.

return HasLocalMutations() || HasCommittedMutations();
}

protected:
bool Equals(const MaybeDocument& other) const override;

private:
FieldValue data_; // This is of type Object.
bool has_local_mutations_;
DocumentState document_state_;
};

/** Compares against another Document. */
inline bool operator==(const Document& lhs, const Document& rhs) {
return lhs.version() == rhs.version() && lhs.key() == rhs.key() &&
lhs.has_local_mutations() == rhs.has_local_mutations() &&
lhs.HasLocalMutations() == rhs.HasLocalMutations() &&
lhs.data() == rhs.data();
}

Expand Down
16 changes: 15 additions & 1 deletion Firestore/core/src/firebase/firestore/model/maybe_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ class MaybeDocument {
public:
/**
* All the different kinds of documents, including MaybeDocument and its
* subclasses. This is used to provide RTTI for documents.
* subclasses. This is used to provide RTTI for documents. See the docstrings
* of the subclasses for details.
*/
enum class Type {
// An unknown subclass of MaybeDocument. This should never happen.
//
// TODO(rsgowman): Since it's no longer possible to directly create
// MaybeDocument's, we can likely remove this value entirely. But
// investigate impact on the serializers first.
Unknown,

Document,
NoDocument,
UnknownDocument,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you are adding type here, could you add document for each of the type? In particular, it helps reader differing Unknown and UnknownDocument.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer not to add documentation for each type, since that can already be found in the subclasses themselves. So instead, I've added "See the docstrings of the subclasses for details." to the docstring of the enum itself.

However, "Unknown" isn't a subclass. It used to be used by MaybeDocument in situations where a MaybeDocument was created directly. That's no longer possible since MaybeDocument is now abstract. It's also used as a placeholder for an invalid value that indicates a pretty serious problem with serialization. I've added a docstring for this value.

I've also added a TODO to investigate removing it entirely; I suspect the serializers can do without it.

};

MaybeDocument(DocumentKey key, SnapshotVersion version);
Expand All @@ -66,6 +74,12 @@ class MaybeDocument {
return version_;
}

/**
* Whether this document has a local mutation applied that has not yet been
* acknowledged by Watch.
*/
virtual bool HasPendingWrites() const = 0;

protected:
// Only allow subclass to set their types.
void set_type(Type type) {
Expand Down
10 changes: 3 additions & 7 deletions Firestore/core/src/firebase/firestore/model/mutation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::shared_ptr<const MaybeDocument> SetMutation::ApplyToLocalView(

SnapshotVersion version = GetPostMutationVersion(maybe_doc.get());
return absl::make_unique<Document>(FieldValue(value_), key(), version,
/*has_local_mutations=*/true);
DocumentState::kLocalMutations);
}

PatchMutation::PatchMutation(DocumentKey&& key,
Expand All @@ -84,17 +84,13 @@ std::shared_ptr<const MaybeDocument> PatchMutation::ApplyToLocalView(
VerifyKeyMatches(maybe_doc.get());

if (!precondition().IsValidFor(maybe_doc.get())) {
if (maybe_doc) {
return absl::make_unique<MaybeDocument>(maybe_doc->key(),
maybe_doc->version());
}
return nullptr;
return maybe_doc;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

It fixes a bug (or at least an implementation difference):

  • This is how the other ports do this.
  • The tests (added in this PR) check to see that the returned maybe_doc is the same as the one passed in.

(Additionally, I can no longer create a MaybeDocument since it's now an abstract class. But that wasn't the reason I made this change.)

The ownership semantics around this aren't particularly solid, as might be expected when porting from a language where that's less important. Ideally, we might go back and rework this, and then backport to the other languages, but that's not super high priority at the moment.

}

SnapshotVersion version = GetPostMutationVersion(maybe_doc.get());
FieldValue new_data = PatchDocument(maybe_doc.get());
return absl::make_unique<Document>(std::move(new_data), key(), version,
/*has_local_mutations=*/true);
DocumentState::kLocalMutations);
}

FieldValue PatchMutation::PatchDocument(const MaybeDocument* maybe_doc) const {
Expand Down
7 changes: 5 additions & 2 deletions Firestore/core/src/firebase/firestore/model/no_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ namespace firebase {
namespace firestore {
namespace model {

NoDocument::NoDocument(DocumentKey key, SnapshotVersion version)
: MaybeDocument(std::move(key), std::move(version)) {
NoDocument::NoDocument(DocumentKey key,
SnapshotVersion version,
bool has_committed_mutations)
: MaybeDocument(std::move(key), std::move(version)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit: moving SnapshotVersion is no more efficient than copying it (unless there's an expectation this class will grow) (here and in some other constructors)

Copy link
Member Author

Choose a reason for hiding this comment

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

For non-primitive types, I usually just std::move it, unless it's really obvious that the thing is small. (really obvious => documented as small.) We can probably assume that with SnapshotVersion (and Timestamp), since it seems unlikely that either will grow.

Somewhat related: http://go/c-readability-advice#value-param

Proposal: Since you've called this optional, and since we std::move SnapshotVersion's (and probably Timestamp's too) somewhat inconsistently in the rest of the code, I'll defer this for now. But I'll create a followup inspired by the above readability link that:
a) ensures std::is_trivially_copyable()
b) ensures sizeof <= 16
for these types, and then:
c) remove usages of std::move and const&.

has_committed_mutations_(has_committed_mutations) {
set_type(Type::NoDocument);
}

Expand Down
11 changes: 10 additions & 1 deletion Firestore/core/src/firebase/firestore/model/no_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ namespace model {
/** Represents that no documents exists for the key at the given version. */
class NoDocument : public MaybeDocument {
public:
NoDocument(DocumentKey key, SnapshotVersion version);
NoDocument(DocumentKey key,
SnapshotVersion version,
bool has_committed_mutations);

bool HasPendingWrites() const override {
return has_committed_mutations_;
}

private:
bool has_committed_mutations_;
};

} // namespace model
Expand Down
32 changes: 32 additions & 0 deletions Firestore/core/src/firebase/firestore/model/unknown_document.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Firestore/core/src/firebase/firestore/model/unknown_document.h"

#include <utility>

namespace firebase {
namespace firestore {
namespace model {

UnknownDocument::UnknownDocument(DocumentKey key, SnapshotVersion version)
: MaybeDocument(std::move(key), std::move(version)) {
set_type(Type::UnknownDocument);
}

} // namespace model
} // namespace firestore
} // namespace firebase
Loading