22
22
#include " Firestore/core/src/model/mutable_document.h"
23
23
#include " Firestore/core/src/model/mutation_batch.h"
24
24
#include " Firestore/core/src/nanopb/byte_string.h"
25
+ #include " Firestore/core/src/util/hard_assert.h"
25
26
26
27
namespace firebase {
27
28
namespace firestore {
@@ -43,9 +44,11 @@ void CountingQueryEngine::SetLocalDocumentsView(
43
44
local_documents->remote_document_cache (), this );
44
45
mutation_queue_ = absl::make_unique<WrappedMutationQueue>(
45
46
local_documents->mutation_queue (), this );
47
+ document_overlay_cache_ = absl::make_unique<WrappedDocumentOverlayCache>(
48
+ local_documents->document_overlay_cache (), this );
46
49
local_documents_ = absl::make_unique<LocalDocumentsView>(
47
50
remote_documents_.get (), mutation_queue_.get (),
48
- local_documents->index_manager ());
51
+ document_overlay_cache_. get (), local_documents->index_manager ());
49
52
QueryEngine::SetLocalDocumentsView (local_documents_.get ());
50
53
}
51
54
@@ -54,6 +57,9 @@ void CountingQueryEngine::ResetCounts() {
54
57
mutations_read_by_key_ = 0 ;
55
58
documents_read_by_query_ = 0 ;
56
59
documents_read_by_key_ = 0 ;
60
+ overlays_read_by_key_ = 0 ;
61
+ overlays_read_by_collection_ = 0 ;
62
+ overlays_read_by_collection_group_ = 0 ;
57
63
}
58
64
59
65
// MARK: - WrappedMutationQueue
@@ -173,6 +179,44 @@ model::MutableDocumentMap WrappedRemoteDocumentCache::GetMatching(
173
179
return result;
174
180
}
175
181
182
+ // MARK: - WrappedDocumentOverlayCache
183
+
184
+ absl::optional<model::Overlay> WrappedDocumentOverlayCache::GetOverlay (
185
+ const model::DocumentKey& key) const {
186
+ ++query_engine_->overlays_read_by_key_ ;
187
+ return subject_->GetOverlay (key);
188
+ }
189
+
190
+ void WrappedDocumentOverlayCache::SaveOverlays (
191
+ int largest_batch_id, const MutationByDocumentKeyMap& overlays) {
192
+ subject_->SaveOverlays (largest_batch_id, overlays);
193
+ }
194
+
195
+ void WrappedDocumentOverlayCache::RemoveOverlaysForBatchId (int batch_id) {
196
+ subject_->RemoveOverlaysForBatchId (batch_id);
197
+ }
198
+
199
+ DocumentOverlayCache::OverlayByDocumentKeyMap
200
+ WrappedDocumentOverlayCache::GetOverlays (const model::ResourcePath& collection,
201
+ int since_batch_id) const {
202
+ auto result = subject_->GetOverlays (collection, since_batch_id);
203
+ query_engine_->overlays_read_by_collection_ += result.size ();
204
+ return result;
205
+ }
206
+
207
+ DocumentOverlayCache::OverlayByDocumentKeyMap
208
+ WrappedDocumentOverlayCache::GetOverlays (absl::string_view collection_group,
209
+ int since_batch_id,
210
+ std::size_t count) const {
211
+ auto result = subject_->GetOverlays (collection_group, since_batch_id, count);
212
+ query_engine_->overlays_read_by_collection_group_ += result.size ();
213
+ return result;
214
+ }
215
+
216
+ int WrappedDocumentOverlayCache::GetOverlayCount () const {
217
+ HARD_FAIL (" WrappedDocumentOverlayCache::GetOverlayCount() not implemented" );
218
+ }
219
+
176
220
} // namespace local
177
221
} // namespace firestore
178
222
} // namespace firebase
0 commit comments