15
15
package com .google .firebase .firestore .local ;
16
16
17
17
import androidx .annotation .Nullable ;
18
- import com .google .firebase .Timestamp ;
19
18
import com .google .firebase .database .collection .ImmutableSortedMap ;
20
19
import com .google .firebase .database .collection .ImmutableSortedSet ;
21
20
import com .google .firebase .firestore .core .Query ;
26
25
import com .google .firebase .firestore .model .ResourcePath ;
27
26
import com .google .firebase .firestore .model .SnapshotVersion ;
28
27
import com .google .firebase .firestore .model .mutation .Mutation ;
29
- import com .google .firebase .firestore .model .mutation .MutationBatch ;
30
- import com .google .protobuf .ByteString ;
28
+ import com .google .firebase .firestore .model .mutation .Overlay ;
31
29
import java .util .Collection ;
32
- import java .util .List ;
33
30
import java .util .Map ;
34
31
35
32
/**
39
36
class CountingQueryEngine extends QueryEngine {
40
37
private final QueryEngine queryEngine ;
41
38
42
- private final int [] mutationsReadByCollection = new int [] {0 };
43
- private final int [] mutationsReadByKey = new int [] {0 };
39
+ private final int [] overlaysReadByCollection = new int [] {0 };
40
+ private final int [] overlaysReadByKey = new int [] {0 };
44
41
private final int [] documentsReadByCollection = new int [] {0 };
45
42
private final int [] documentsReadByKey = new int [] {0 };
46
43
@@ -49,8 +46,8 @@ class CountingQueryEngine extends QueryEngine {
49
46
}
50
47
51
48
void resetCounts () {
52
- mutationsReadByCollection [0 ] = 0 ;
53
- mutationsReadByKey [0 ] = 0 ;
49
+ overlaysReadByCollection [0 ] = 0 ;
50
+ overlaysReadByKey [0 ] = 0 ;
54
51
documentsReadByCollection [0 ] = 0 ;
55
52
documentsReadByKey [0 ] = 0 ;
56
53
}
@@ -60,9 +57,9 @@ public void initialize(LocalDocumentsView localDocuments, IndexManager indexMana
60
57
LocalDocumentsView wrappedView =
61
58
new LocalDocumentsView (
62
59
wrapRemoteDocumentCache (localDocuments .getRemoteDocumentCache ()),
63
- wrapMutationQueue ( localDocuments .getMutationQueue () ),
64
- localDocuments .getDocumentOverlayCache (),
65
- localDocuments . getIndexManager () );
60
+ localDocuments .getMutationQueue (),
61
+ wrapOverlayCache ( localDocuments .getDocumentOverlayCache () ),
62
+ indexManager );
66
63
queryEngine .initialize (wrappedView , indexManager );
67
64
}
68
65
@@ -96,20 +93,19 @@ int getDocumentsReadByKey() {
96
93
}
97
94
98
95
/**
99
- * Returns the number of mutations returned by the MutationQueue's
100
- * `getAllMutationBatchesAffectingQuery()` API (since the last call to `resetCounts()`)
96
+ * Returns the number of mutations returned by the OverlayCache's `getOverlays()` API (since the
97
+ * last call to `resetCounts()`)
101
98
*/
102
- int getMutationsReadByCollection () {
103
- return mutationsReadByCollection [0 ];
99
+ int getOverlaysReadByCollection () {
100
+ return overlaysReadByCollection [0 ];
104
101
}
105
102
106
103
/**
107
- * Returns the number of mutations returned by the MutationQueue's
108
- * `getAllMutationBatchesAffectingDocumentKey()` and
109
- * `getAllMutationBatchesAffectingDocumentKeys()` APIs (since the last call to `resetCounts()`)
104
+ * Returns the number of mutations returned by the OverlayCache's `getOverlay()` API (since the
105
+ * last call to `resetCounts()`)
110
106
*/
111
- int getMutationsReadByKey () {
112
- return mutationsReadByKey [0 ];
107
+ int getOverlaysReadByKey () {
108
+ return overlaysReadByKey [0 ];
113
109
}
114
110
115
111
private RemoteDocumentCache wrapRemoteDocumentCache (RemoteDocumentCache subject ) {
@@ -168,96 +164,40 @@ public SnapshotVersion getLatestReadTime() {
168
164
};
169
165
}
170
166
171
- private MutationQueue wrapMutationQueue (MutationQueue subject ) {
172
- return new MutationQueue () {
173
- @ Override
174
- public void start () {
175
- subject .start ();
176
- }
177
-
178
- @ Override
179
- public boolean isEmpty () {
180
- return subject .isEmpty ();
181
- }
182
-
183
- @ Override
184
- public void acknowledgeBatch (MutationBatch batch , ByteString streamToken ) {
185
- subject .acknowledgeBatch (batch , streamToken );
186
- }
187
-
188
- @ Override
189
- public ByteString getLastStreamToken () {
190
- return subject .getLastStreamToken ();
191
- }
192
-
193
- @ Override
194
- public void setLastStreamToken (ByteString streamToken ) {
195
- subject .setLastStreamToken (streamToken );
196
- }
197
-
198
- @ Override
199
- public MutationBatch addMutationBatch (
200
- Timestamp localWriteTime , List <Mutation > baseMutations , List <Mutation > mutations ) {
201
- return subject .addMutationBatch (localWriteTime , baseMutations , mutations );
202
- }
203
-
167
+ private DocumentOverlayCache wrapOverlayCache (DocumentOverlayCache subject ) {
168
+ return new DocumentOverlayCache () {
204
169
@ Nullable
205
170
@ Override
206
- public MutationBatch lookupMutationBatch (int batchId ) {
207
- return subject .lookupMutationBatch (batchId );
171
+ public Overlay getOverlay (DocumentKey key ) {
172
+ ++overlaysReadByKey [0 ];
173
+ return subject .getOverlay (key );
208
174
}
209
175
210
- @ Nullable
211
176
@ Override
212
- public MutationBatch getNextMutationBatchAfterBatchId (int batchId ) {
213
- return subject .getNextMutationBatchAfterBatchId ( batchId );
177
+ public void saveOverlays (int largestBatchId , Map < DocumentKey , Mutation > overlays ) {
178
+ subject .saveOverlays ( largestBatchId , overlays );
214
179
}
215
180
216
181
@ Override
217
- public int getHighestUnacknowledgedBatchId ( ) {
218
- return subject .getHighestUnacknowledgedBatchId ( );
182
+ public void removeOverlaysForBatchId ( int batchId ) {
183
+ subject .removeOverlaysForBatchId ( batchId );
219
184
}
220
185
221
186
@ Override
222
- public List < MutationBatch > getAllMutationBatches ( ) {
223
- List < MutationBatch > result = subject .getAllMutationBatches ( );
224
- mutationsReadByKey [0 ] += result .size ();
187
+ public Map < DocumentKey , Overlay > getOverlays ( ResourcePath collection , int sinceBatchId ) {
188
+ Map < DocumentKey , Overlay > result = subject .getOverlays ( collection , sinceBatchId );
189
+ overlaysReadByCollection [0 ] += result .size ();
225
190
return result ;
226
191
}
227
192
228
193
@ Override
229
- public List <MutationBatch > getAllMutationBatchesAffectingDocumentKey (
230
- DocumentKey documentKey ) {
231
- List <MutationBatch > result = subject .getAllMutationBatchesAffectingDocumentKey (documentKey );
232
- mutationsReadByKey [0 ] += result .size ();
194
+ public Map <DocumentKey , Overlay > getOverlays (
195
+ String collectionGroup , int sinceBatchId , int count ) {
196
+ Map <DocumentKey , Overlay > result =
197
+ subject .getOverlays (collectionGroup , sinceBatchId , count );
198
+ overlaysReadByCollection [0 ] += result .size ();
233
199
return result ;
234
200
}
235
-
236
- @ Override
237
- public List <MutationBatch > getAllMutationBatchesAffectingDocumentKeys (
238
- Iterable <DocumentKey > documentKeys ) {
239
- List <MutationBatch > result =
240
- subject .getAllMutationBatchesAffectingDocumentKeys (documentKeys );
241
- mutationsReadByKey [0 ] += result .size ();
242
- return result ;
243
- }
244
-
245
- @ Override
246
- public List <MutationBatch > getAllMutationBatchesAffectingQuery (Query query ) {
247
- List <MutationBatch > result = subject .getAllMutationBatchesAffectingQuery (query );
248
- mutationsReadByCollection [0 ] += result .size ();
249
- return result ;
250
- }
251
-
252
- @ Override
253
- public void removeMutationBatch (MutationBatch batch ) {
254
- subject .removeMutationBatch (batch );
255
- }
256
-
257
- @ Override
258
- public void performConsistencyCheck () {
259
- subject .performConsistencyCheck ();
260
- }
261
201
};
262
202
}
263
203
}
0 commit comments