Skip to content

Commit

Permalink
move index auto creation works with mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
dconeybe committed Sep 1, 2023
1 parent e78b1a6 commit 469f3d6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 46 deletions.
41 changes: 0 additions & 41 deletions packages/firestore/test/unit/local/local_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2758,47 +2758,6 @@ function indexedDbLocalStoreTests(
}

// TODO(dconeybe) port this test next
it('index auto creation works with mutation', () => {
const query_ = query(
'coll',
filter('value', 'array-contains-any', [8, 1, 'string'])
);
return expectLocalStore()
.afterAllocatingQuery(query_)
.toReturnTargetId(2)
.afterIndexAutoCreationConfigure({
isEnabled: true,
indexAutoCreationMinCollectionSize: 0,
relativeIndexReadCostPerDocument: 2
})
.afterRemoteEvents([
docAddedRemoteEvent(
doc('coll/a', 10, { value: [8, 1, 'string'] }),
[2],
[]
),
docAddedRemoteEvent(doc('coll/b', 10, { value: [] }), [2], []),
docAddedRemoteEvent(doc('coll/c', 10, { value: [3] }), [2], []),
docAddedRemoteEvent(doc('coll/d', 10, { value: [0, 5] }), [2], []),
docAddedRemoteEvent(doc('coll/e', 10, { value: ['string'] }), [2], [])
])
.afterExecutingQuery(query_)
.toHaveRead({ documentsByKey: 0, documentsByCollection: 2 })
.toReturnChanged('coll/a', 'coll/e')
.afterMutation(deleteMutation('coll/e'))
.afterBackfillIndexes()
.afterMutation(setMutation('coll/f', { value: [1] }))
.afterExecutingQuery(query_)
.toHaveRead({
documentsByKey: 1,
documentsByCollection: 0,
overlaysByKey: 1,
overlaysByCollection: 1
})
.toReturnChanged('coll/a', 'coll/f')
.finish();
});

it('delete all indexes works with index auto creation', () => {
const query_ = query('coll', filter('value', '==', 'match'));
return (
Expand Down
41 changes: 36 additions & 5 deletions packages/firestore/test/unit/local/local_store_indexeddb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class AsyncLocalStoreTester {
assertOverlaysRead(
byKey: number,
byCollection: number,
overlayTypes: { [k: string]: MutationType }
overlayTypes?: { [k: string]: MutationType }
): void {
expect(this.queryEngine.overlaysReadByCollection).to.equal(
byCollection,
Expand All @@ -191,10 +191,12 @@ class AsyncLocalStoreTester {
byKey,
'Overlays read (by key)'
);
expect(this.queryEngine.overlayTypes).to.deep.equal(
overlayTypes,
'Overlay types read'
);
if (overlayTypes) {
expect(this.queryEngine.overlayTypes).to.deep.equal(
overlayTypes,
'Overlay types read'
);
}
}

assertQueryReturned(...keys: string[]): void {
Expand Down Expand Up @@ -687,4 +689,33 @@ describe('LocalStore w/ IndexedDB Persistence (Non generic)', () => {
test.assertRemoteDocumentsRead(0, 2);
});

it('index auto creation works with mutation', async () => {
const query_ = query('coll', filter('value', 'array-contains-any', [8, 1, 'string']));

const targetId = await test.allocateQuery(query_);
test.configureIndexAutoCreation({
isEnabled: true,
indexAutoCreationMinCollectionSize: 0,
relativeIndexReadCostPerDocument: 2
});

await test.applyRemoteEvent(docAddedRemoteEvent(doc('coll/a', 10, { value: [8, 1, 'string'] }), [targetId]));
await test.applyRemoteEvent(docAddedRemoteEvent(doc('coll/b', 10, { value: [] }), [targetId]));
await test.applyRemoteEvent(docAddedRemoteEvent(doc('coll/c', 10, { value: [3] }), [targetId]));
await test.applyRemoteEvent(docAddedRemoteEvent(doc('coll/d', 10, { value: [0, 5] }), [targetId]));
await test.applyRemoteEvent(docAddedRemoteEvent(doc('coll/e', 10, { value: ['string'] }), [targetId]));

await test.executeQuery(query_);
test.assertRemoteDocumentsRead(0, 2);
test.assertQueryReturned('coll/a', 'coll/e');

await test.writeMutations(deleteMutation('coll/e'));
await test.backfillIndexes();
await test.writeMutations(setMutation('coll/f', { value: [1] }));

await test.executeQuery(query_);
test.assertRemoteDocumentsRead(1, 0);
test.assertOverlaysRead(1, 1);
test.assertQueryReturned('coll/a', 'coll/f');
});
});

0 comments on commit 469f3d6

Please sign in to comment.