Skip to content

Commit 47c046e

Browse files
authored
Add IndexConfiguration CRUD to IndexManager (#9348)
1 parent 8dae747 commit 47c046e

16 files changed

+801
-43
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
08E3D48B3651E4908D75B23A /* async_testing.cc in Sources */ = {isa = PBXBuildFile; fileRef = 872C92ABD71B12784A1C5520 /* async_testing.cc */; };
5858
08F44F7DF9A3EF0D35C8FB57 /* FIRNumericTransformTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = D5B25E7E7D6873CBA4571841 /* FIRNumericTransformTests.mm */; };
5959
08FA4102AD14452E9587A1F2 /* leveldb_util_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 332485C4DCC6BA0DBB5E31B7 /* leveldb_util_test.cc */; };
60-
0929C73B3F3BFC331E9E9D2F /* resource.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1C3F7302BF4AE6CBC00ECDD0 /* resource.pb.cc */; };
6160
095A878BB33211AB52BFAD9F /* leveldb_document_overlay_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AE89CFF09C6804573841397F /* leveldb_document_overlay_cache_test.cc */; };
61+
0929C73B3F3BFC331E9E9D2F /* resource.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1C3F7302BF4AE6CBC00ECDD0 /* resource.pb.cc */; };
6262
0963F6D7B0F9AE1E24B82866 /* path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 403DBF6EFB541DFD01582AA3 /* path_test.cc */; };
6363
096BA3A3703AC1491F281618 /* index.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 395E8B07639E69290A929695 /* index.pb.cc */; };
6464
098191405BA24F9A7E4F80C6 /* append_only_list_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5477CDE922EE71C8000FCC1E /* append_only_list_test.cc */; };

Firestore/core/src/local/index_manager.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
#include <string>
2121
#include <vector>
2222

23+
#include "Firestore/core/src/model/model_fwd.h"
24+
2325
namespace firebase {
2426
namespace firestore {
2527

28+
namespace core {
29+
class Target;
30+
class SortedMap;
31+
} // namespace core
32+
2633
namespace model {
34+
class DocumentKey;
35+
class FieldIndex;
36+
class IndexOffset;
2737
class ResourcePath;
2838
} // namespace model
2939

@@ -39,6 +49,9 @@ class IndexManager {
3949
public:
4050
virtual ~IndexManager() = default;
4151

52+
/** Initializes the IndexManager. */
53+
virtual void Start() = 0;
54+
4255
/**
4356
* Creates an index entry mapping the collection_id (last segment of the path)
4457
* to the parent path (either the containing document location or the empty
@@ -58,6 +71,65 @@ class IndexManager {
5871
*/
5972
virtual std::vector<model::ResourcePath> GetCollectionParents(
6073
const std::string& collection_id) = 0;
74+
75+
/**
76+
* Adds a field path index.
77+
*
78+
* The actual entries for this index will be created and persisted in the
79+
* background by the SDK, and the index will be used for query execution once
80+
* values are persisted.
81+
*/
82+
virtual void AddFieldIndex(const model::FieldIndex& index) = 0;
83+
84+
/** Removes the given field index and deletes all index values. */
85+
virtual void DeleteFieldIndex(const model::FieldIndex& index) = 0;
86+
87+
/**
88+
* Returns a list of field indexes that correspond to the specified collection
89+
* group.
90+
*/
91+
virtual std::vector<model::FieldIndex> GetFieldIndexes(
92+
const std::string& collection_group) = 0;
93+
94+
/** Returns all configured field indexes. */
95+
virtual std::vector<model::FieldIndex> GetFieldIndexes() = 0;
96+
97+
/**
98+
* Returns an index that can be used to serve the provided target. Returns
99+
* `nullopt` if no index is configured.
100+
*/
101+
virtual absl::optional<model::FieldIndex> GetFieldIndex(
102+
core::Target target) = 0;
103+
104+
/**
105+
* Returns the documents that match the given target based on the provided
106+
* index, or `nullopt` if the query cannot be served from an index.
107+
*/
108+
virtual absl::optional<std::vector<model::DocumentKey>>
109+
GetDocumentsMatchingTarget(model::FieldIndex fieldIndex,
110+
core::Target target) = 0;
111+
112+
/**
113+
* Returns the next collection group to update. Returns `nullopt` if no
114+
* group exists.
115+
*/
116+
virtual absl::optional<std::string> GetNextCollectionGroupToUpdate() = 0;
117+
118+
/**
119+
* Sets the collection group's latest read time.
120+
*
121+
* This method updates the index offset for all field indices for the
122+
* collection group and increments their sequence number.
123+
*
124+
* Subsequent calls to `GetNextCollectionGroupToUpdate()` will return a
125+
* different collection group (unless only one collection group is
126+
* configured).
127+
*/
128+
virtual void UpdateCollectionGroup(const std::string& collection_group,
129+
model::IndexOffset offset) = 0;
130+
131+
/** Updates the index entries for the provided documents. */
132+
virtual void UpdateIndexEntries(const model::DocumentMap& documents) = 0;
61133
};
62134

63135
} // namespace local

0 commit comments

Comments
 (0)