Skip to content

Commit 5e01dfc

Browse files
authored
firestore::mutation::Overlay class added (#9301)
1 parent ae31586 commit 5e01dfc

File tree

7 files changed

+419
-1
lines changed

7 files changed

+419
-1
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
0A4E1B5E3E853763AE6ED7AE /* grpc_stream_tester.cc in Sources */ = {isa = PBXBuildFile; fileRef = 87553338E42B8ECA05BA987E /* grpc_stream_tester.cc */; };
6060
0A52B47C43B7602EE64F53A7 /* cc_compilation_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1B342370EAE3AA02393E33EB /* cc_compilation_test.cc */; };
6161
0A6FBE65A7FE048BAD562A15 /* FSTGoogleTestTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */; };
62+
0AAC19331BDCCDAA02D22CCB /* overlay_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = DEB1D304BB728BB798719D98 /* overlay_test.cc */; };
6263
0ABCE06A0D96EA3899B3A259 /* query_engine_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B8A853940305237AFDA8050B /* query_engine_test.cc */; };
6364
0AE084A7886BC11B8C305122 /* string_util_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380CFC201A2EE200D97691 /* string_util_test.cc */; };
6465
0B002E2E2012B32EB801C6D5 /* bundle_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 79EAA9F7B1B9592B5F053923 /* bundle_spec_test.json */; };
@@ -221,6 +222,7 @@
221222
2D220B9ABFA36CD7AC43D0A7 /* time_testing.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5497CB76229DECDE000FB92F /* time_testing.cc */; };
222223
2D65D31D71A75B046C47B0EB /* view_testing.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5466E7809AD2871FFDE6C76 /* view_testing.cc */; };
223224
2DB56B6DED2C93014AE5C51A /* write_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 54DA12A51F315EE100DD57A1 /* write_spec_test.json */; };
225+
2DCF3D3E60CE87C72683FD4F /* overlay_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = DEB1D304BB728BB798719D98 /* overlay_test.cc */; };
224226
2E0BBA7E627EB240BA11B0D0 /* exponential_backoff_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6D1B68420E2AB1A00B35856 /* exponential_backoff_test.cc */; };
225227
2E169CF1E9E499F054BB873A /* FSTEventAccumulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */; };
226228
2E373EA9D5FF8C6DE2507675 /* field_index_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = BF76A8DA34B5B67B4DD74666 /* field_index_test.cc */; };
@@ -317,6 +319,7 @@
317319
44EAF3E6EAC0CC4EB2147D16 /* transform_operation_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 33607A3AE91548BD219EC9C6 /* transform_operation_test.cc */; };
318320
4562CDD90F5FF0491F07C5DA /* leveldb_opener_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 75860CD13AF47EB1EA39EC2F /* leveldb_opener_test.cc */; };
319321
457171CE2510EEA46F7D8A30 /* FIRFirestoreTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5467FAFF203E56F8009C9584 /* FIRFirestoreTests.mm */; };
322+
45927566F465117A79C5BB34 /* overlay_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = DEB1D304BB728BB798719D98 /* overlay_test.cc */; };
320323
45939AFF906155EA27D281AB /* annotations.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 618BBE9520B89AAC00B5BCE7 /* annotations.pb.cc */; };
321324
45A5504D33D39C6F80302450 /* async_queue_libdispatch_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = B6FB4680208EA0BE00554BA2 /* async_queue_libdispatch_test.mm */; };
322325
45CECACC11031B4FA6A2F4E8 /* bundle_loader_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = A853C81A6A5A51C9D0389EDA /* bundle_loader_test.cc */; };
@@ -601,6 +604,7 @@
601604
6369DE4E258556FE3382DD78 /* field_filter_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = E8551D6C6FB0B1BACE9E5BAD /* field_filter_test.cc */; };
602605
6380CACCF96A9B26900983DC /* leveldb_target_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = E76F0CDF28E5FA62D21DE648 /* leveldb_target_cache_test.cc */; };
603606
63B91FC476F3915A44F00796 /* query.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 544129D621C2DDC800EFB9CC /* query.pb.cc */; };
607+
64CA849415318C8B54DB8FD0 /* overlay_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = DEB1D304BB728BB798719D98 /* overlay_test.cc */; };
604608
650B31A5EC6F8D2AEA79C350 /* index_manager_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AE4A9E38D65688EE000EE2A1 /* index_manager_test.cc */; };
605609
65537B22A73E3909666FB5BC /* remote_document_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7EB299CF85034F09CFD6F3FD /* remote_document_cache_test.cc */; };
606610
65D54B964A2021E5A36AB21F /* bundle_loader_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = A853C81A6A5A51C9D0389EDA /* bundle_loader_test.cc */; };
@@ -1108,6 +1112,7 @@
11081112
DA1D665B12AA1062DCDEA6BD /* async_queue_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6FB467B208E9A8200554BA2 /* async_queue_test.cc */; };
11091113
DA4303684707606318E1914D /* target_id_generator_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380CF82019382300D97691 /* target_id_generator_test.cc */; };
11101114
DABB9FB61B1733F985CBF713 /* executor_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6FB4688208F9B9100554BA2 /* executor_test.cc */; };
1115+
DAF19F9F1144CFFBBCB5C938 /* overlay_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = DEB1D304BB728BB798719D98 /* overlay_test.cc */; };
11111116
DAFF0CF921E64AC30062958F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DAFF0CF821E64AC30062958F /* AppDelegate.m */; };
11121117
DAFF0CFB21E64AC40062958F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DAFF0CFA21E64AC40062958F /* Assets.xcassets */; };
11131118
DAFF0CFE21E64AC40062958F /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAFF0CFC21E64AC40062958F /* MainMenu.xib */; };
@@ -1248,6 +1253,7 @@
12481253
FABE084FA7DA6E216A41EE80 /* status_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54A0352C20A3B3D7003E0143 /* status_test.cc */; };
12491254
FAD97B82766AEC29B7B5A1B7 /* index_manager_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AE4A9E38D65688EE000EE2A1 /* index_manager_test.cc */; };
12501255
FAE5DA6ED3E1842DC21453EE /* fake_target_metadata_provider.cc in Sources */ = {isa = PBXBuildFile; fileRef = 71140E5D09C6E76F7C71B2FC /* fake_target_metadata_provider.cc */; };
1256+
FAF094D65A12935BEDED81C9 /* overlay_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = DEB1D304BB728BB798719D98 /* overlay_test.cc */; };
12511257
FB2111D9205822CC8E7368C2 /* FIRDocumentReferenceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E049202154AA00B64F25 /* FIRDocumentReferenceTests.mm */; };
12521258
FB2D5208A6B5816A7244D77A /* query_engine_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B8A853940305237AFDA8050B /* query_engine_test.cc */; };
12531259
FB3D9E01547436163C456A3C /* message_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = CE37875365497FFA8687B745 /* message_test.cc */; };
@@ -1661,6 +1667,7 @@
16611667
DE51B1981F0D48AC0013853F /* FSTSpecTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTSpecTests.h; sourceTree = "<group>"; };
16621668
DE51B19A1F0D48AC0013853F /* FSTSyncEngineTestDriver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTSyncEngineTestDriver.h; sourceTree = "<group>"; };
16631669
DE51B1A71F0D48AC0013853F /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
1670+
DEB1D304BB728BB798719D98 /* overlay_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; name = overlay_test.cc; path = mutation/overlay_test.cc; sourceTree = "<group>"; };
16641671
DF148C0D5EEC4A2CD9FA484C /* Pods-Firestore_Example_macOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_macOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_macOS/Pods-Firestore_Example_macOS.release.xcconfig"; sourceTree = "<group>"; };
16651672
E3228F51DCDC2E90D5C58F97 /* ConditionalConformanceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ConditionalConformanceTests.swift; sourceTree = "<group>"; };
16661673
E42355285B9EF55ABD785792 /* Pods_Firestore_Example_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Example_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2315,6 +2322,14 @@
23152322
name = api;
23162323
sourceTree = "<group>";
23172324
};
2325+
A673E8876DA382A08A72E007 /* mutation */ = {
2326+
isa = PBXGroup;
2327+
children = (
2328+
DEB1D304BB728BB798719D98 /* overlay_test.cc */,
2329+
);
2330+
name = mutation;
2331+
sourceTree = "<group>";
2332+
};
23182333
AAEA2A72CFD1FA5AD34462F7 /* Pods */ = {
23192334
isa = PBXGroup;
23202335
children = (
@@ -2349,6 +2364,7 @@
23492364
AB356EF5200E9D1A0089B766 /* model */ = {
23502365
isa = PBXGroup;
23512366
children = (
2367+
A673E8876DA382A08A72E007 /* mutation */,
23522368
AB71064B201FA60300344F18 /* database_id_test.cc */,
23532369
B6152AD5202A5385000E5744 /* document_key_test.cc */,
23542370
547E9A4122F9EA7300A275E0 /* document_set_test.cc */,
@@ -3548,6 +3564,7 @@
35483564
87B5972F1C67CB8D53ADA024 /* object_value_test.cc in Sources */,
35493565
E08297B35E12106105F448EB /* ordered_code_benchmark.cc in Sources */,
35503566
72AD91671629697074F2545B /* ordered_code_test.cc in Sources */,
3567+
64CA849415318C8B54DB8FD0 /* overlay_test.cc in Sources */,
35513568
DB7E9C5A59CCCDDB7F0C238A /* path_test.cc in Sources */,
35523569
E30BF9E316316446371C956C /* persistence_testing.cc in Sources */,
35533570
0455FC6E2A281BD755FD933A /* precondition_test.cc in Sources */,
@@ -3739,6 +3756,7 @@
37393756
F0C8EB1F4FB56401CFA4F374 /* object_value_test.cc in Sources */,
37403757
B3C87C635527A2E57944B789 /* ordered_code_benchmark.cc in Sources */,
37413758
FD8EA96A604E837092ACA51D /* ordered_code_test.cc in Sources */,
3759+
DAF19F9F1144CFFBBCB5C938 /* overlay_test.cc in Sources */,
37423760
0963F6D7B0F9AE1E24B82866 /* path_test.cc in Sources */,
37433761
92D7081085679497DC112EDB /* persistence_testing.cc in Sources */,
37443762
152543FD706D5E8851C8DA92 /* precondition_test.cc in Sources */,
@@ -3944,6 +3962,7 @@
39443962
AFB2455806D7C4100C16713B /* object_value_test.cc in Sources */,
39453963
28691225046DF9DF181B3350 /* ordered_code_benchmark.cc in Sources */,
39463964
E4A573B7C9227C3C24661B5B /* ordered_code_test.cc in Sources */,
3965+
FAF094D65A12935BEDED81C9 /* overlay_test.cc in Sources */,
39473966
70A171FC43BE328767D1B243 /* path_test.cc in Sources */,
39483967
EECC1EC64CA963A8376FA55C /* persistence_testing.cc in Sources */,
39493968
34D69886DAD4A2029BFC5C63 /* precondition_test.cc in Sources */,
@@ -4149,6 +4168,7 @@
41494168
D711B3F495923680B6FC2FC6 /* object_value_test.cc in Sources */,
41504169
71702588BFBF5D3A670508E7 /* ordered_code_benchmark.cc in Sources */,
41514170
B4C675BE9030D5C7D19C4D19 /* ordered_code_test.cc in Sources */,
4171+
2DCF3D3E60CE87C72683FD4F /* overlay_test.cc in Sources */,
41524172
B3A309CCF5D75A555C7196E1 /* path_test.cc in Sources */,
41534173
46EAC2828CD942F27834F497 /* persistence_testing.cc in Sources */,
41544174
9EE1447AA8E68DF98D0590FF /* precondition_test.cc in Sources */,
@@ -4350,6 +4370,7 @@
43504370
1EE2B61B15AAA7C864188A59 /* object_value_test.cc in Sources */,
43514371
3040FD156E1B7C92B0F2A70C /* ordered_code_benchmark.cc in Sources */,
43524372
AB380D04201BC6E400D97691 /* ordered_code_test.cc in Sources */,
4373+
45927566F465117A79C5BB34 /* overlay_test.cc in Sources */,
43534374
5A080105CCBFDB6BF3F3772D /* path_test.cc in Sources */,
43544375
21C17F15579341289AD01051 /* persistence_testing.cc in Sources */,
43554376
549CCA5920A36E1F00BCEB75 /* precondition_test.cc in Sources */,
@@ -4574,6 +4595,7 @@
45744595
DF7ABEB48A650117CBEBCD26 /* object_value_test.cc in Sources */,
45754596
4FAB27F13EA5D3D79E770EA2 /* ordered_code_benchmark.cc in Sources */,
45764597
21836C4D9D48F962E7A3A244 /* ordered_code_test.cc in Sources */,
4598+
0AAC19331BDCCDAA02D22CCB /* overlay_test.cc in Sources */,
45774599
6105A1365831B79A7DEEA4F3 /* path_test.cc in Sources */,
45784600
CB8BEF34CC4A996C7BE85119 /* persistence_testing.cc in Sources */,
45794601
4194B7BB8B0352E1AC5D69B9 /* precondition_test.cc in Sources */,

Firestore/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ firebase_ios_glob(
203203
src/local/*.h
204204
src/model/*.cc
205205
src/model/*.h
206+
src/model/mutation/*.cc
207+
src/model/mutation/*.h
206208
src/nanopb/*.cc
207209
src/nanopb/*.h
208210
src/objc/*.h

Firestore/core/src/model/model_fwd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class Message;
5858

5959
namespace model {
6060

61+
namespace mutation {
62+
63+
class Overlay;
64+
65+
} // namespace mutation
66+
6167
class DatabaseId;
6268
class DeleteMutation;
6369
class Document;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "Firestore/core/src/model/mutation/overlay.h"
18+
19+
#include <iostream>
20+
21+
#include "Firestore/core/src/util/hashing.h"
22+
#include "Firestore/core/src/util/to_string.h"
23+
#include "absl/strings/str_cat.h"
24+
25+
namespace firebase {
26+
namespace firestore {
27+
namespace model {
28+
namespace mutation {
29+
30+
bool operator==(const Overlay& lhs, const Overlay& rhs) {
31+
return lhs.largest_batch_id_ == rhs.largest_batch_id_ &&
32+
lhs.mutation_ == rhs.mutation_;
33+
}
34+
35+
std::ostream& operator<<(std::ostream& os, const Overlay& result) {
36+
return os << result.ToString();
37+
}
38+
39+
std::size_t Overlay::Hash() const {
40+
if (mutation_.is_valid()) {
41+
return util::Hash(largest_batch_id_, mutation_);
42+
} else {
43+
return util::Hash(largest_batch_id_, -1);
44+
}
45+
}
46+
47+
std::string Overlay::ToString() const {
48+
return absl::StrCat("Overlay(largest_batch_id=", largest_batch_id_,
49+
", mutation=", util::ToString(mutation_), ")");
50+
}
51+
52+
std::size_t OverlayHash::operator()(const Overlay& overlay) const {
53+
return overlay.Hash();
54+
}
55+
56+
} // namespace mutation
57+
} // namespace model
58+
} // namespace firestore
59+
} // namespace firebase
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIRESTORE_CORE_SRC_MODEL_MUTATION_OVERLAY_H_
18+
#define FIRESTORE_CORE_SRC_MODEL_MUTATION_OVERLAY_H_
19+
20+
#include <cstdlib>
21+
#include <iosfwd>
22+
#include <string>
23+
#include <utility>
24+
25+
#include "Firestore/core/src/model/document_key.h"
26+
#include "Firestore/core/src/model/mutation.h"
27+
28+
namespace firebase {
29+
namespace firestore {
30+
namespace model {
31+
namespace mutation {
32+
33+
/**
34+
* Representation of an overlay computed by Firestore.
35+
*
36+
* Holds information about a mutation and the largest batch id in Firestore when
37+
* the mutation was created.
38+
*/
39+
class Overlay {
40+
public:
41+
Overlay() = default;
42+
43+
Overlay(int largest_batch_id, const Mutation& mutation)
44+
: largest_batch_id_(largest_batch_id), mutation_(mutation) {
45+
}
46+
47+
int largest_batch_id() const {
48+
return largest_batch_id_;
49+
}
50+
51+
const Mutation& mutation() const {
52+
return mutation_;
53+
}
54+
55+
const DocumentKey& key() const {
56+
return mutation_.key();
57+
}
58+
59+
std::size_t Hash() const;
60+
61+
std::string ToString() const;
62+
63+
friend bool operator==(const Overlay&, const Overlay&);
64+
friend std::ostream& operator<<(std::ostream&, const Overlay&);
65+
66+
private:
67+
int largest_batch_id_ = -1;
68+
Mutation mutation_;
69+
};
70+
71+
bool operator==(const Overlay&, const Overlay&);
72+
73+
inline bool operator!=(const Overlay& lhs, const Overlay& rhs) {
74+
return !(lhs == rhs);
75+
}
76+
77+
std::ostream& operator<<(std::ostream&, const Overlay&);
78+
79+
struct OverlayHash {
80+
std::size_t operator()(const Overlay&) const;
81+
};
82+
83+
} // namespace mutation
84+
} // namespace model
85+
} // namespace firestore
86+
} // namespace firebase
87+
88+
#endif // FIRESTORE_CORE_SRC_MODEL_MUTATION_OVERLAY_H_

Firestore/core/test/unit/model/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
firebase_ios_glob(
16-
sources *.cc *.h
16+
sources *.cc *.h mutation/*.cc mutation/*.h
1717
)
1818

1919
if(FIREBASE_IOS_BUILD_TESTS)
@@ -22,6 +22,7 @@ if(FIREBASE_IOS_BUILD_TESTS)
2222
target_link_libraries(
2323
firestore_model_test PRIVATE
2424
GMock::GMock
25+
absl_strings
2526
firestore_core
2627
firestore_testutil
2728
)

0 commit comments

Comments
 (0)