-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Port FSTMemoryQueryCache to C++ #2197
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
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fcd5062
Port leveldb remote document cache
6e794b7
Style
8b6318c
Review feedback
78650a6
Remove foundation import
c6781b2
Move foundation import to implementation file
3389e12
Start work on remote document cache interface port
204d8c4
Mark inheritance
6624923
Merge master
6e50b12
Checkpoint porting FSTRemoteDocumentCache
45a1e2f
Port FSTRemoteDocumentCacheTest to use C++ interface
5f735c0
Merge in test port
43e8609
Remove FSTRemoteDocumentCache
02b2b58
style
7bb91f5
Merge branch 'master' into rdc
f2f2672
Fix warnings
7bc391e
Style and remove cast
5bdf42b
Drop commented-out code
cd97a9e
Review feedback
26c7962
Start on memory query cache
22f6f9f
Merge branch 'master' into memory_query_cache
d2c7c5e
Cleanup after porting
04a040d
Add move
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
Firestore/core/src/firebase/firestore/local/memory_query_cache.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_MEMORY_QUERY_CACHE_H_ | ||
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_MEMORY_QUERY_CACHE_H_ | ||
|
||
#if !defined(__OBJC__) | ||
#error "For now, this file must only be included by ObjC source files." | ||
#endif // !defined(__OBJC__) | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#include <cstdint> | ||
#include <utility> | ||
|
||
#include "Firestore/core/src/firebase/firestore/model/document_key_set.h" | ||
#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" | ||
#include "Firestore/core/src/firebase/firestore/model/types.h" | ||
|
||
@class FSTLocalSerializer; | ||
@class FSTMemoryPersistence; | ||
@class FSTQuery; | ||
@class FSTQueryData; | ||
@class FSTReferenceSet; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
namespace local { | ||
|
||
typedef void (^TargetEnumerator)(FSTQueryData*, BOOL*); | ||
|
||
class MemoryQueryCache { | ||
public: | ||
explicit MemoryQueryCache(FSTMemoryPersistence* persistence); | ||
|
||
// Target-related methods | ||
void AddTarget(FSTQueryData* query_data); | ||
|
||
void UpdateTarget(FSTQueryData* query_data); | ||
|
||
void RemoveTarget(FSTQueryData* query_data); | ||
|
||
FSTQueryData* _Nullable GetTarget(FSTQuery* query); | ||
|
||
void EnumerateTargets(TargetEnumerator block); | ||
|
||
int RemoveTargets(model::ListenSequenceNumber upper_bound, | ||
NSDictionary<NSNumber*, FSTQueryData*>* live_targets); | ||
|
||
// Key-related methods | ||
void AddMatchingKeys(const model::DocumentKeySet& keys, | ||
model::TargetId target_id); | ||
|
||
void RemoveMatchingKeys(const model::DocumentKeySet& keys, | ||
model::TargetId target_id); | ||
|
||
void RemoveAllKeysForTarget(model::TargetId target_id); | ||
|
||
model::DocumentKeySet GetMatchingKeys(model::TargetId target_id); | ||
|
||
bool Contains(const model::DocumentKey& key); | ||
|
||
// Other methods and accessors | ||
size_t CalculateByteSize(FSTLocalSerializer* serializer); | ||
|
||
int32_t count() const { | ||
return static_cast<int32_t>([queries_ count]); | ||
} | ||
|
||
model::ListenSequenceNumber highest_listen_sequence_number() const { | ||
return highest_listen_sequence_number_; | ||
} | ||
|
||
model::TargetId highest_target_id() const { | ||
return highest_target_id_; | ||
} | ||
|
||
const model::SnapshotVersion& last_remote_snapshot_version() const { | ||
return last_remote_snapshot_version_; | ||
} | ||
|
||
void set_last_remote_snapshot_version(model::SnapshotVersion version) { | ||
last_remote_snapshot_version_ = std::move(version); | ||
} | ||
|
||
private: | ||
FSTMemoryPersistence* persistence_; | ||
/** The highest sequence number encountered */ | ||
model::ListenSequenceNumber highest_listen_sequence_number_; | ||
/** The highest numbered target ID encountered. */ | ||
model::TargetId highest_target_id_; | ||
/** The last received snapshot version. */ | ||
model::SnapshotVersion last_remote_snapshot_version_; | ||
|
||
/** Maps a query to the data about that query. */ | ||
NSMutableDictionary<FSTQuery*, FSTQueryData*>* queries_; | ||
/** A ordered bidirectional mapping between documents and the remote target | ||
* IDs. */ | ||
FSTReferenceSet* references_; | ||
}; | ||
|
||
} // namespace local | ||
} // namespace firestore | ||
} // namespace firebase | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_MEMORY_QUERY_CACHE_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since in the iimplementation you are calling
last_remote_snapshot_version_ = std::move(version);
it is consistent to call with_cache->set_last_remote_snapshot_version(std::move(snapshotVersion));
as well. Or you can fix the line below to removestd::move
. Either callingstd::move
or not (consistently) forSnapshotVersion
type is fine since that type is simple and easy to copy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it for consistency, since it seems like someone wanted it at some point.