@@ -20,43 +20,36 @@ import { SnapshotVersion } from '../../../src/core/snapshot_version';
20
20
import { DocumentOverlayCache } from '../../../src/local/document_overlay_cache' ;
21
21
import { IndexManager } from '../../../src/local/index_manager' ;
22
22
import { LocalDocumentsView } from '../../../src/local/local_documents_view' ;
23
- import { MutationQueue } from '../../../src/local/mutation_queue' ;
24
23
import { PersistencePromise } from '../../../src/local/persistence_promise' ;
25
24
import { PersistenceTransaction } from '../../../src/local/persistence_transaction' ;
26
25
import { QueryEngine } from '../../../src/local/query_engine' ;
27
26
import { RemoteDocumentCache } from '../../../src/local/remote_document_cache' ;
28
- import {
29
- DocumentKeySet ,
30
- DocumentMap ,
31
- OverlayMap
32
- } from '../../../src/model/collections' ;
33
- import { DocumentKey } from '../../../src/model/document_key' ;
34
- import { Overlay } from '../../../src/model/overlay' ;
35
- import { ResourcePath } from '../../../src/model/path' ;
27
+ import { DocumentKeySet , DocumentMap } from '../../../src/model/collections' ;
28
+ import { MutationType } from '../../../src/model/mutation' ;
36
29
37
30
/**
38
31
* A test-only query engine that forwards all API calls and exposes the number
39
32
* of documents and mutations read.
40
33
*/
41
34
export class CountingQueryEngine extends QueryEngine {
42
35
/**
43
- * The number of mutations returned by the MutationQueue 's
44
- * `getAllMutationBatchesAffectingQuery( )` API (since the last call to
36
+ * The number of overlays returned by the DocumentOverlayCache 's
37
+ * `getOverlaysByCollection(Group )` API (since the last call to
45
38
* `resetCounts()`)
46
39
*/
47
- mutationsReadByCollection = 0 ;
40
+ overlaysReadByCollection = 0 ;
48
41
49
42
/**
50
- * The number of mutations returned by the MutationQueue's
51
- * `getAllMutationBatchesAffectingDocumentKey()` and
52
- * `getAllMutationBatchesAffectingDocumentKeys()` APIs (since the last call
53
- * to `resetCounts()`)
43
+ * The number of overlays returned by the DocumentOverlayCache's
44
+ * `getOverlay(s)` APIs (since the last call to `resetCounts()`)
54
45
*/
55
- mutationsReadByKey = 0 ;
46
+ overlaysReadByKey = 0 ;
47
+
48
+ overlayTypes : { [ k : string ] : MutationType } = { } ;
56
49
57
50
/**
58
51
* The number of documents returned by the RemoteDocumentCache's
59
- * `getAll()` API (since the last call to `resetCounts()`)
52
+ * `getAll()` API (since the last call to `resetCounts()`).
60
53
*/
61
54
documentsReadByCollection = 0 ;
62
55
@@ -66,25 +59,12 @@ export class CountingQueryEngine extends QueryEngine {
66
59
*/
67
60
documentsReadByKey = 0 ;
68
61
69
- /**
70
- * The number of documents returned by the OverlayCache's `getOverlays()`
71
- * API (since the last call to `resetCounts()`)
72
- */
73
- overlaysReadByCollection = 0 ;
74
-
75
- /**
76
- * The number of documents returned by the OverlayCache's `getOverlay()`
77
- * APIs (since the last call to `resetCounts()`)
78
- */
79
- overlaysReadByKey = 0 ;
80
-
81
62
resetCounts ( ) : void {
82
- this . mutationsReadByCollection = 0 ;
83
- this . mutationsReadByKey = 0 ;
84
- this . documentsReadByCollection = 0 ;
85
- this . documentsReadByKey = 0 ;
86
63
this . overlaysReadByCollection = 0 ;
87
64
this . overlaysReadByKey = 0 ;
65
+ this . overlayTypes = { } ;
66
+ this . documentsReadByCollection = 0 ;
67
+ this . documentsReadByKey = 0 ;
88
68
}
89
69
90
70
getDocumentsMatchingQuery (
@@ -107,8 +87,8 @@ export class CountingQueryEngine extends QueryEngine {
107
87
) : void {
108
88
const view = new LocalDocumentsView (
109
89
this . wrapRemoteDocumentCache ( localDocuments . remoteDocumentCache ) ,
110
- this . wrapMutationQueue ( localDocuments . mutationQueue ) ,
111
- this . wrapDocumentOverlayCache ( localDocuments . documentOverlayCache ) ,
90
+ localDocuments . mutationQueue ,
91
+ this . wrapOverlayCache ( localDocuments . documentOverlayCache ) ,
112
92
localDocuments . indexManager
113
93
) ;
114
94
return super . initialize ( view , indexManager ) ;
@@ -168,88 +148,48 @@ export class CountingQueryEngine extends QueryEngine {
168
148
} ;
169
149
}
170
150
171
- private wrapMutationQueue ( subject : MutationQueue ) : MutationQueue {
151
+ private wrapOverlayCache (
152
+ subject : DocumentOverlayCache
153
+ ) : DocumentOverlayCache {
172
154
return {
173
- addMutationBatch : subject . addMutationBatch ,
174
- checkEmpty : subject . checkEmpty ,
175
- getAllMutationBatches : transaction => {
176
- return subject . getAllMutationBatches ( transaction ) . next ( result => {
177
- this . mutationsReadByKey += result . length ;
155
+ getOverlay : ( transaction , key ) => {
156
+ return subject . getOverlay ( transaction , key ) . next ( result => {
157
+ this . overlaysReadByKey += 1 ;
158
+ if ( ! ! result ) {
159
+ this . overlayTypes [ key . toString ( ) ] = result . mutation . type ;
160
+ }
178
161
return result ;
179
162
} ) ;
180
163
} ,
181
- getAllMutationBatchesAffectingDocumentKey : ( transaction , documentKey ) => {
182
- return subject
183
- . getAllMutationBatchesAffectingDocumentKey ( transaction , documentKey )
184
- . next ( result => {
185
- this . mutationsReadByKey += result . length ;
186
- return result ;
187
- } ) ;
188
- } ,
189
- getAllMutationBatchesAffectingDocumentKeys : (
190
- transaction ,
191
- documentKeys
192
- ) => {
193
- return subject
194
- . getAllMutationBatchesAffectingDocumentKeys ( transaction , documentKeys )
195
- . next ( result => {
196
- this . mutationsReadByKey += result . length ;
197
- return result ;
198
- } ) ;
199
- } ,
200
- getAllMutationBatchesAffectingQuery : ( transaction , query ) => {
201
- return subject
202
- . getAllMutationBatchesAffectingQuery ( transaction , query )
203
- . next ( result => {
204
- this . mutationsReadByCollection += result . length ;
205
- return result ;
164
+
165
+ getOverlays : ( transaction , keys ) => {
166
+ return subject . getOverlays ( transaction , keys ) . next ( result => {
167
+ this . overlaysReadByKey += keys . length ;
168
+ result . forEach ( ( key , overlay ) => {
169
+ this . overlayTypes [ key . toString ( ) ] = overlay . mutation . type ;
206
170
} ) ;
171
+ return result ;
172
+ } ) ;
207
173
} ,
208
- getHighestUnacknowledgedBatchId : subject . getHighestUnacknowledgedBatchId ,
209
- getNextMutationBatchAfterBatchId :
210
- subject . getNextMutationBatchAfterBatchId ,
211
- lookupMutationBatch : subject . lookupMutationBatch ,
212
- performConsistencyCheck : subject . performConsistencyCheck ,
213
- removeMutationBatch : subject . removeMutationBatch
214
- } ;
215
- }
216
174
217
- private wrapDocumentOverlayCache (
218
- subject : DocumentOverlayCache
219
- ) : DocumentOverlayCache {
220
- return {
221
- getOverlay : (
222
- transaction : PersistenceTransaction ,
223
- key : DocumentKey
224
- ) : PersistencePromise < Overlay | null > => {
225
- this . overlaysReadByKey ++ ;
226
- return subject . getOverlay ( transaction , key ) ;
227
- } ,
228
- getOverlays : (
229
- transaction : PersistenceTransaction ,
230
- keys : DocumentKey [ ]
231
- ) : PersistencePromise < OverlayMap > => {
232
- this . overlaysReadByKey += keys . length ;
233
- return subject . getOverlays ( transaction , keys ) ;
234
- } ,
235
- getOverlaysForCollection : (
236
- transaction : PersistenceTransaction ,
237
- collection : ResourcePath ,
238
- sinceBatchId : number
239
- ) : PersistencePromise < OverlayMap > => {
175
+ getOverlaysForCollection : ( transaction , collection , sinceBatchId ) => {
240
176
return subject
241
177
. getOverlaysForCollection ( transaction , collection , sinceBatchId )
242
178
. next ( result => {
243
179
this . overlaysReadByCollection += result . size ( ) ;
180
+ result . forEach ( ( key , overlay ) => {
181
+ this . overlayTypes [ key . toString ( ) ] = overlay . mutation . type ;
182
+ } ) ;
244
183
return result ;
245
184
} ) ;
246
185
} ,
186
+
247
187
getOverlaysForCollectionGroup : (
248
188
transaction : PersistenceTransaction ,
249
189
collectionGroup : string ,
250
190
sinceBatchId : number ,
251
191
count : number
252
- ) : PersistencePromise < OverlayMap > => {
192
+ ) => {
253
193
return subject
254
194
. getOverlaysForCollectionGroup (
255
195
transaction ,
@@ -259,11 +199,24 @@ export class CountingQueryEngine extends QueryEngine {
259
199
)
260
200
. next ( result => {
261
201
this . overlaysReadByCollection += result . size ( ) ;
202
+ result . forEach ( ( key , overlay ) => {
203
+ this . overlayTypes [ key . toString ( ) ] = overlay . mutation . type ;
204
+ } ) ;
262
205
return result ;
263
206
} ) ;
264
207
} ,
265
- removeOverlaysForBatchId : subject . removeOverlaysForBatchId ,
266
- saveOverlays : subject . saveOverlays
208
+
209
+ saveOverlays : ( transaction , largestBatchId , overlays ) => {
210
+ return subject . saveOverlays ( transaction , largestBatchId , overlays ) ;
211
+ } ,
212
+
213
+ removeOverlaysForBatchId : ( transaction , documentKeys , batchId ) => {
214
+ return subject . removeOverlaysForBatchId (
215
+ transaction ,
216
+ documentKeys ,
217
+ batchId
218
+ ) ;
219
+ }
267
220
} ;
268
221
}
269
222
}
0 commit comments