Skip to content

Commit 27ed845

Browse files
Use interfaces for IndexedDB (#6029)
1 parent 2b98b28 commit 27ed845

17 files changed

+1200
-1106
lines changed

packages/firestore/src/local/indexeddb_bundle_cache.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import {
2222
} from '../protos/firestore_bundle_proto';
2323

2424
import { BundleCache } from './bundle_cache';
25+
import { DbBundle, DbNamedQuery } from './indexeddb_schema';
2526
import {
26-
DbBundle,
2727
DbBundlesKey,
28+
DbBundleStore,
2829
DbNamedQueriesKey,
29-
DbNamedQuery
30-
} from './indexeddb_schema';
30+
DbNamedQueryStore
31+
} from './indexeddb_sentinels';
3132
import { getStore } from './indexeddb_transaction';
3233
import {
3334
fromDbBundle,
@@ -89,7 +90,7 @@ export class IndexedDbBundleCache implements BundleCache {
8990
function bundlesStore(
9091
txn: PersistenceTransaction
9192
): SimpleDbStore<DbBundlesKey, DbBundle> {
92-
return getStore<DbBundlesKey, DbBundle>(txn, DbBundle.store);
93+
return getStore<DbBundlesKey, DbBundle>(txn, DbBundleStore);
9394
}
9495

9596
/**
@@ -98,5 +99,5 @@ function bundlesStore(
9899
function namedQueriesStore(
99100
txn: PersistenceTransaction
100101
): SimpleDbStore<DbNamedQueriesKey, DbNamedQuery> {
101-
return getStore<DbNamedQueriesKey, DbNamedQuery>(txn, DbNamedQuery.store);
102+
return getStore<DbNamedQueriesKey, DbNamedQuery>(txn, DbNamedQueryStore);
102103
}

packages/firestore/src/local/indexeddb_document_overlay_cache.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ import { ResourcePath } from '../model/path';
2424

2525
import { DocumentOverlayCache } from './document_overlay_cache';
2626
import { encodeResourcePath } from './encoded_resource_path';
27-
import { DbDocumentOverlay, DbDocumentOverlayKey } from './indexeddb_schema';
27+
import { DbDocumentOverlay } from './indexeddb_schema';
28+
import {
29+
DbDocumentOverlayCollectionGroupOverlayIndex,
30+
DbDocumentOverlayCollectionPathOverlayIndex,
31+
DbDocumentOverlayKey,
32+
DbDocumentOverlayStore
33+
} from './indexeddb_sentinels';
2834
import { getStore } from './indexeddb_transaction';
2935
import {
3036
fromDbDocumentOverlay,
@@ -106,7 +112,7 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
106112
);
107113
promises.push(
108114
documentOverlayStore(transaction).deleteAll(
109-
DbDocumentOverlay.collectionPathOverlayIndex,
115+
DbDocumentOverlayCollectionPathOverlayIndex,
110116
range
111117
)
112118
);
@@ -129,7 +135,7 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
129135
/*lowerOpen=*/ true
130136
);
131137
return documentOverlayStore(transaction)
132-
.loadAll(DbDocumentOverlay.collectionPathOverlayIndex, range)
138+
.loadAll(DbDocumentOverlayCollectionPathOverlayIndex, range)
133139
.next(dbOverlays => {
134140
for (const dbOverlay of dbOverlays) {
135141
const overlay = fromDbDocumentOverlay(this.serializer, dbOverlay);
@@ -157,7 +163,7 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
157163
return documentOverlayStore(transaction)
158164
.iterate(
159165
{
160-
index: DbDocumentOverlay.collectionGroupOverlayIndex,
166+
index: DbDocumentOverlayCollectionGroupOverlayIndex,
161167
range
162168
},
163169
(_, dbOverlay, control) => {
@@ -198,6 +204,6 @@ function documentOverlayStore(
198204
): SimpleDbStore<DbDocumentOverlayKey, DbDocumentOverlay> {
199205
return getStore<DbDocumentOverlayKey, DbDocumentOverlay>(
200206
txn,
201-
DbDocumentOverlay.store
207+
DbDocumentOverlayStore
202208
);
203209
}

packages/firestore/src/local/indexeddb_index_manager.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,23 @@ import {
6464
import { IndexManager } from './index_manager';
6565
import {
6666
DbCollectionParent,
67-
DbCollectionParentKey,
6867
DbIndexConfiguration,
69-
DbIndexConfigurationKey,
7068
DbIndexEntry,
71-
DbIndexEntryKey,
72-
DbIndexState,
73-
DbIndexStateKey
69+
DbIndexState
7470
} from './indexeddb_schema';
71+
import {
72+
DbCollectionParentKey,
73+
DbCollectionParentStore,
74+
DbIndexConfigurationCollectionGroupIndex,
75+
DbIndexConfigurationKey,
76+
DbIndexConfigurationStore,
77+
DbIndexEntryDocumentKeyIndex,
78+
DbIndexEntryKey,
79+
DbIndexEntryStore,
80+
DbIndexStateKey,
81+
DbIndexStateSequenceNumberIndex,
82+
DbIndexStateStore
83+
} from './indexeddb_sentinels';
7584
import { getStore } from './indexeddb_transaction';
7685
import {
7786
fromDbIndexConfiguration,
@@ -311,7 +320,7 @@ export class IndexedDbIndexManager implements IndexManager {
311320
}
312321

313322
/**
314-
* Constructs a key range query on `DbIndexEntry.store` that unions all
323+
* Constructs a key range query on `DbIndexEntryStore` that unions all
315324
* bounds.
316325
*/
317326
private generateIndexRanges(
@@ -586,7 +595,7 @@ export class IndexedDbIndexManager implements IndexManager {
586595
return (
587596
collectionGroup
588597
? indexes.loadAll(
589-
DbIndexConfiguration.collectionGroupIndex,
598+
DbIndexConfigurationCollectionGroupIndex,
590599
IDBKeyRange.bound(collectionGroup, collectionGroup)
591600
)
592601
: indexes.loadAll()
@@ -632,7 +641,7 @@ export class IndexedDbIndexManager implements IndexManager {
632641
return this.getNextSequenceNumber(transaction).next(nextSequenceNumber =>
633642
indexes
634643
.loadAll(
635-
DbIndexConfiguration.collectionGroupIndex,
644+
DbIndexConfigurationCollectionGroupIndex,
636645
IDBKeyRange.bound(collectionGroup, collectionGroup)
637646
)
638647
.next(configs =>
@@ -701,15 +710,13 @@ export class IndexedDbIndexManager implements IndexManager {
701710
indexEntry: IndexEntry
702711
): PersistencePromise<void> {
703712
const indexEntries = indexEntriesStore(transaction);
704-
return indexEntries.put(
705-
new DbIndexEntry(
706-
indexEntry.indexId,
707-
this.uid,
708-
indexEntry.arrayValue,
709-
indexEntry.directionalValue,
710-
encodeResourcePath(document.key.path)
711-
)
712-
);
713+
return indexEntries.put({
714+
indexId: indexEntry.indexId,
715+
uid: this.uid,
716+
arrayValue: indexEntry.arrayValue,
717+
directionalValue: indexEntry.directionalValue,
718+
documentKey: encodeResourcePath(document.key.path)
719+
});
713720
}
714721

715722
private deleteIndexEntry(
@@ -737,7 +744,7 @@ export class IndexedDbIndexManager implements IndexManager {
737744
return indexEntries
738745
.iterate(
739746
{
740-
index: DbIndexEntry.documentKeyIndex,
747+
index: DbIndexEntryDocumentKeyIndex,
741748
range: IDBKeyRange.only([
742749
fieldIndex.indexId,
743750
this.uid,
@@ -839,7 +846,7 @@ export class IndexedDbIndexManager implements IndexManager {
839846
return states
840847
.iterate(
841848
{
842-
index: DbIndexState.sequenceNumberIndex,
849+
index: DbIndexStateSequenceNumberIndex,
843850
reverse: true,
844851
range: IDBKeyRange.upperBound([this.uid, Number.MAX_SAFE_INTEGER])
845852
},
@@ -924,7 +931,7 @@ function collectionParentsStore(
924931
): SimpleDbStore<DbCollectionParentKey, DbCollectionParent> {
925932
return getStore<DbCollectionParentKey, DbCollectionParent>(
926933
txn,
927-
DbCollectionParent.store
934+
DbCollectionParentStore
928935
);
929936
}
930937

@@ -934,7 +941,7 @@ function collectionParentsStore(
934941
function indexEntriesStore(
935942
txn: PersistenceTransaction
936943
): SimpleDbStore<DbIndexEntryKey, DbIndexEntry> {
937-
return getStore<DbIndexEntryKey, DbIndexEntry>(txn, DbIndexEntry.store);
944+
return getStore<DbIndexEntryKey, DbIndexEntry>(txn, DbIndexEntryStore);
938945
}
939946

940947
/**
@@ -945,7 +952,7 @@ function indexConfigurationStore(
945952
): SimpleDbStore<DbIndexConfigurationKey, DbIndexConfiguration> {
946953
return getStore<DbIndexConfigurationKey, DbIndexConfiguration>(
947954
txn,
948-
DbIndexConfiguration.store
955+
DbIndexConfigurationStore
949956
);
950957
}
951958

@@ -955,5 +962,5 @@ function indexConfigurationStore(
955962
function indexStateStore(
956963
txn: PersistenceTransaction
957964
): SimpleDbStore<DbIndexStateKey, DbIndexState> {
958-
return getStore<DbIndexStateKey, DbIndexState>(txn, DbIndexState.store);
965+
return getStore<DbIndexStateKey, DbIndexState>(txn, DbIndexStateStore);
959966
}

packages/firestore/src/local/indexeddb_lru_delegate_impl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { IndexedDbLruDelegate } from './indexeddb_lru_delegate';
2929
import { mutationQueuesContainKey } from './indexeddb_mutation_queue';
3030
import { DbTargetDocument } from './indexeddb_schema';
31+
import { DbTargetDocumentDocumentTargetsIndex } from './indexeddb_sentinels';
3132
import {
3233
documentTargetStore,
3334
IndexedDbTargetCache
@@ -201,7 +202,7 @@ export class IndexedDbLruDelegateImpl implements IndexedDbLruDelegate {
201202
return store
202203
.iterate(
203204
{
204-
index: DbTargetDocument.documentTargetsIndex
205+
index: DbTargetDocumentDocumentTargetsIndex
205206
},
206207
([targetId, docKey], { path, sequenceNumber }) => {
207208
if (targetId === 0) {
@@ -250,7 +251,7 @@ function sentinelRow(
250251
key: DocumentKey,
251252
sequenceNumber: ListenSequenceNumber
252253
): DbTargetDocument {
253-
return new DbTargetDocument(0, encodeResourcePath(key.path), sequenceNumber);
254+
return { targetId: 0, path: encodeResourcePath(key.path), sequenceNumber };
254255
}
255256

256257
function writeSentinelKey(

packages/firestore/src/local/indexeddb_mutation_batch_impl.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ import { fail, hardAssert } from '../util/assert';
2020

2121
import {
2222
DbDocumentMutation,
23-
DbDocumentMutationKey,
2423
DbMutationBatch,
25-
DbMutationBatchKey,
2624
DbRemoteDocument
2725
} from './indexeddb_schema';
26+
import {
27+
DbDocumentMutationKey,
28+
DbDocumentMutationStore,
29+
DbMutationBatchKey,
30+
DbMutationBatchStore,
31+
newDbDocumentMutationKey
32+
} from './indexeddb_sentinels';
2833
import { PersistencePromise } from './persistence_promise';
2934
import { SimpleDbTransaction } from './simple_db';
3035

@@ -38,10 +43,10 @@ export function removeMutationBatch(
3843
batch: { batchId: number; mutations: Array<{ key: DocumentKey }> }
3944
): PersistencePromise<DocumentKey[]> {
4045
const mutationStore = txn.store<DbMutationBatchKey, DbMutationBatch>(
41-
DbMutationBatch.store
46+
DbMutationBatchStore
4247
);
4348
const indexTxn = txn.store<DbDocumentMutationKey, DbDocumentMutation>(
44-
DbDocumentMutation.store
49+
DbDocumentMutationStore
4550
);
4651
const promises: Array<PersistencePromise<void>> = [];
4752

@@ -65,7 +70,7 @@ export function removeMutationBatch(
6570
);
6671
const removedDocuments: DocumentKey[] = [];
6772
for (const mutation of batch.mutations) {
68-
const indexKey = DbDocumentMutation.key(
73+
const indexKey = newDbDocumentMutationKey(
6974
userId,
7075
mutation.key.path,
7176
batch.batchId

0 commit comments

Comments
 (0)