Skip to content

Index-Free: Port LocalStore tests #2173

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 17 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/firestore/src/local/local_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ export class LocalStore {
* Returns the QueryData as seen by the LocalStore, including updates that may
* have not yet been persisted to the QueryCache.
*/
// Visible for testing.
getQueryData(
transaction: PersistenceTransaction,
query: Query
Expand Down
45 changes: 31 additions & 14 deletions packages/firestore/test/unit/local/counting_query_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,39 @@ import { DocumentKeySet, DocumentMap } from '../../../src/model/collections';
*/
export class CountingQueryEngine implements QueryEngine {
/**
* The number of mutations returned by the MutationQueue (since the last call
* The number of mutations returned by the MutationQueue's
* `getAllMutationBatchesAffectingQuery()` API (since the last call to
* `resetCounts()`)
*/
mutationsReadByQuery = 0;

/**
* The number of mutations returned by the MutationQueue's
* `getAllMutationBatchesAffectingDocumentKey()` and
* `getAllMutationBatchesAffectingDocumentKeys()` APIs (since the last call
* to `resetCounts()`)
*/
mutationsRead = 0;
mutationsReadByKey = 0;

/**
* The number of documents returned by the RemoteDocumentCache's
* `getDocumentsMatchingQuery()` API (since the last call to `resetCounts()`)
*/
documentsReadByQuery = 0;

/**
* The number of documents returned by the RemoteDocumentCache (since the
* last call to `resetCounts()`)
* The number of documents returned by the RemoteDocumentCache's `getEntry()`
* and `getEntries()` APIs (since the last call to `resetCounts()`)
*/
documentsRead = 0;
documentsReadByKey = 0;

constructor(private readonly queryEngine: QueryEngine) {}

resetCounts(): void {
this.mutationsRead = 0;
this.documentsRead = 0;
this.mutationsReadByQuery = 0;
this.mutationsReadByKey = 0;
this.documentsReadByQuery = 0;
this.documentsReadByKey = 0;
}

getDocumentsMatchingQuery(
Expand Down Expand Up @@ -81,19 +98,19 @@ export class CountingQueryEngine implements QueryEngine {
return subject
.getDocumentsMatchingQuery(transaction, query, sinceReadTime)
.next(result => {
this.documentsRead += result.size;
this.documentsReadByQuery += result.size;
return result;
});
},
getEntries: (transaction, documentKeys) => {
return subject.getEntries(transaction, documentKeys).next(result => {
this.documentsRead += result.size;
this.documentsReadByKey += result.size;
return result;
});
},
getEntry: (transaction, documentKey) => {
return subject.getEntry(transaction, documentKey).next(result => {
this.documentsRead += result ? 1 : 0;
this.documentsReadByKey += result ? 1 : 0;
return result;
});
},
Expand All @@ -110,15 +127,15 @@ export class CountingQueryEngine implements QueryEngine {
checkEmpty: subject.checkEmpty,
getAllMutationBatches: transaction => {
return subject.getAllMutationBatches(transaction).next(result => {
this.mutationsRead += result.length;
this.mutationsReadByKey += result.length;
return result;
});
},
getAllMutationBatchesAffectingDocumentKey: (transaction, documentKey) => {
return subject
.getAllMutationBatchesAffectingDocumentKey(transaction, documentKey)
.next(result => {
this.mutationsRead += result.length;
this.mutationsReadByKey += result.length;
return result;
});
},
Expand All @@ -129,15 +146,15 @@ export class CountingQueryEngine implements QueryEngine {
return subject
.getAllMutationBatchesAffectingDocumentKeys(transaction, documentKeys)
.next(result => {
this.mutationsRead += result.length;
this.mutationsReadByKey += result.length;
return result;
});
},
getAllMutationBatchesAffectingQuery: (transaction, query) => {
return subject
.getAllMutationBatchesAffectingQuery(transaction, query)
.next(result => {
this.mutationsRead += result.length;
this.mutationsReadByQuery += result.length;
return result;
});
},
Expand Down
Loading