Skip to content

Add IndexConfiguration CRUD to IndexManager #9348

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 11 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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: 1 addition & 1 deletion Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
08E3D48B3651E4908D75B23A /* async_testing.cc in Sources */ = {isa = PBXBuildFile; fileRef = 872C92ABD71B12784A1C5520 /* async_testing.cc */; };
08F44F7DF9A3EF0D35C8FB57 /* FIRNumericTransformTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = D5B25E7E7D6873CBA4571841 /* FIRNumericTransformTests.mm */; };
08FA4102AD14452E9587A1F2 /* leveldb_util_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 332485C4DCC6BA0DBB5E31B7 /* leveldb_util_test.cc */; };
0929C73B3F3BFC331E9E9D2F /* resource.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1C3F7302BF4AE6CBC00ECDD0 /* resource.pb.cc */; };
095A878BB33211AB52BFAD9F /* leveldb_document_overlay_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AE89CFF09C6804573841397F /* leveldb_document_overlay_cache_test.cc */; };
0929C73B3F3BFC331E9E9D2F /* resource.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1C3F7302BF4AE6CBC00ECDD0 /* resource.pb.cc */; };
0963F6D7B0F9AE1E24B82866 /* path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 403DBF6EFB541DFD01582AA3 /* path_test.cc */; };
096BA3A3703AC1491F281618 /* index.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 395E8B07639E69290A929695 /* index.pb.cc */; };
098191405BA24F9A7E4F80C6 /* append_only_list_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5477CDE922EE71C8000FCC1E /* append_only_list_test.cc */; };
Expand Down
68 changes: 68 additions & 0 deletions Firestore/core/src/local/index_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@
#include <string>
#include <vector>

#include "Firestore/core/src/model/model_fwd.h"

namespace firebase {
namespace firestore {

namespace core {
class Target;
class SortedMap;
} // namespace core

namespace model {
class DocumentKey;
class FieldIndex;
class IndexOffset;
class ResourcePath;
} // namespace model

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

/** Initializes the IndexManager. */
virtual void Start() = 0;

/**
* Creates an index entry mapping the collection_id (last segment of the path)
* to the parent path (either the containing document location or the empty
Expand All @@ -58,6 +71,61 @@ class IndexManager {
*/
virtual std::vector<model::ResourcePath> GetCollectionParents(
const std::string& collection_id) = 0;

/**
* Adds a field path index.
*
* Values for this index are persisted asynchronously. The index will only be
* used for query execution once values are persisted.
*/
virtual void AddFieldIndex(const model::FieldIndex& index) = 0;

/** Removes the given field index and deletes all index values. */
virtual void DeleteFieldIndex(const model::FieldIndex& index) = 0;

/**
* Returns a list of field indexes that correspond to the specified collection
* group.
*/
virtual std::vector<model::FieldIndex> GetFieldIndexes(
const std::string& collection_group) = 0;

/** Returns all configured field indexes. */
virtual std::vector<model::FieldIndex> GetFieldIndexes() = 0;

/**
* Returns an index that can be used to serve the provided target. Returns
* `nullopt` if no index is configured.
*/
virtual absl::optional<model::FieldIndex> GetFieldIndex(
core::Target target) = 0;

/** Returns the documents that match the given target based on the provided
* index. */
virtual std::vector<model::DocumentKey> GetDocumentsMatchingTarget(
model::FieldIndex fieldIndex, core::Target target) = 0;

/**
* Returns the next collection group to update. Returns `nullopt` if no
* group exists.
*/
virtual absl::optional<std::string> GetNextCollectionGroupToUpdate() = 0;

/**
* Sets the collection group's latest read time.
*
* This method updates the index offset for all field indices for the
* collection group and increments their sequence number.
*
* Subsequent calls to `GetNextCollectionGroupToUpdate()` will return a
* different collection group (unless only one collection group is
* configured).
*/
virtual void UpdateCollectionGroup(const std::string& collection_group,
model::IndexOffset offset) = 0;

/** Updates the index entries for the provided documents. */
virtual void UpdateIndexEntries(const model::DocumentMap& documents) = 0;
};

} // namespace local
Expand Down
Loading