Skip to content

Commit 7a3a2d1

Browse files
Index-Free: Port LocalStore tests (#2173)
1 parent 539ab0d commit 7a3a2d1

File tree

4 files changed

+554
-213
lines changed

4 files changed

+554
-213
lines changed

packages/firestore/src/local/local_store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ export class LocalStore {
784784
* Returns the QueryData as seen by the LocalStore, including updates that may
785785
* have not yet been persisted to the QueryCache.
786786
*/
787+
// Visible for testing.
787788
getQueryData(
788789
transaction: PersistenceTransaction,
789790
query: Query

packages/firestore/test/unit/local/counting_query_engine.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,39 @@ import { DocumentKeySet, DocumentMap } from '../../../src/model/collections';
3131
*/
3232
export class CountingQueryEngine implements QueryEngine {
3333
/**
34-
* The number of mutations returned by the MutationQueue (since the last call
34+
* The number of mutations returned by the MutationQueue's
35+
* `getAllMutationBatchesAffectingQuery()` API (since the last call to
36+
* `resetCounts()`)
37+
*/
38+
mutationsReadByQuery = 0;
39+
40+
/**
41+
* The number of mutations returned by the MutationQueue's
42+
* `getAllMutationBatchesAffectingDocumentKey()` and
43+
* `getAllMutationBatchesAffectingDocumentKeys()` APIs (since the last call
3544
* to `resetCounts()`)
3645
*/
37-
mutationsRead = 0;
46+
mutationsReadByKey = 0;
47+
48+
/**
49+
* The number of documents returned by the RemoteDocumentCache's
50+
* `getDocumentsMatchingQuery()` API (since the last call to `resetCounts()`)
51+
*/
52+
documentsReadByQuery = 0;
3853

3954
/**
40-
* The number of documents returned by the RemoteDocumentCache (since the
41-
* last call to `resetCounts()`)
55+
* The number of documents returned by the RemoteDocumentCache's `getEntry()`
56+
* and `getEntries()` APIs (since the last call to `resetCounts()`)
4257
*/
43-
documentsRead = 0;
58+
documentsReadByKey = 0;
4459

4560
constructor(private readonly queryEngine: QueryEngine) {}
4661

4762
resetCounts(): void {
48-
this.mutationsRead = 0;
49-
this.documentsRead = 0;
63+
this.mutationsReadByQuery = 0;
64+
this.mutationsReadByKey = 0;
65+
this.documentsReadByQuery = 0;
66+
this.documentsReadByKey = 0;
5067
}
5168

5269
getDocumentsMatchingQuery(
@@ -81,19 +98,19 @@ export class CountingQueryEngine implements QueryEngine {
8198
return subject
8299
.getDocumentsMatchingQuery(transaction, query, sinceReadTime)
83100
.next(result => {
84-
this.documentsRead += result.size;
101+
this.documentsReadByQuery += result.size;
85102
return result;
86103
});
87104
},
88105
getEntries: (transaction, documentKeys) => {
89106
return subject.getEntries(transaction, documentKeys).next(result => {
90-
this.documentsRead += result.size;
107+
this.documentsReadByKey += result.size;
91108
return result;
92109
});
93110
},
94111
getEntry: (transaction, documentKey) => {
95112
return subject.getEntry(transaction, documentKey).next(result => {
96-
this.documentsRead += result ? 1 : 0;
113+
this.documentsReadByKey += result ? 1 : 0;
97114
return result;
98115
});
99116
},
@@ -110,15 +127,15 @@ export class CountingQueryEngine implements QueryEngine {
110127
checkEmpty: subject.checkEmpty,
111128
getAllMutationBatches: transaction => {
112129
return subject.getAllMutationBatches(transaction).next(result => {
113-
this.mutationsRead += result.length;
130+
this.mutationsReadByKey += result.length;
114131
return result;
115132
});
116133
},
117134
getAllMutationBatchesAffectingDocumentKey: (transaction, documentKey) => {
118135
return subject
119136
.getAllMutationBatchesAffectingDocumentKey(transaction, documentKey)
120137
.next(result => {
121-
this.mutationsRead += result.length;
138+
this.mutationsReadByKey += result.length;
122139
return result;
123140
});
124141
},
@@ -129,15 +146,15 @@ export class CountingQueryEngine implements QueryEngine {
129146
return subject
130147
.getAllMutationBatchesAffectingDocumentKeys(transaction, documentKeys)
131148
.next(result => {
132-
this.mutationsRead += result.length;
149+
this.mutationsReadByKey += result.length;
133150
return result;
134151
});
135152
},
136153
getAllMutationBatchesAffectingQuery: (transaction, query) => {
137154
return subject
138155
.getAllMutationBatchesAffectingQuery(transaction, query)
139156
.next(result => {
140-
this.mutationsRead += result.length;
157+
this.mutationsReadByQuery += result.length;
141158
return result;
142159
});
143160
},

0 commit comments

Comments
 (0)