Skip to content

Commit ed87b76

Browse files
authored
Rename QueryData and QueryCache to TargetData and TargetCache (#2333)
* QueryCache -> TargetCache * Rename QueryData -> TargetData * Rename QueryPurpose -> TargetPurpose
1 parent 332250d commit ed87b76

29 files changed

+692
-675
lines changed

packages/firestore/src/core/sync_engine.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import { User } from '../auth/user';
1919
import { LocalStore } from '../local/local_store';
2020
import { LocalViewChanges } from '../local/local_view_changes';
21-
import { QueryData, QueryPurpose } from '../local/query_data';
2221
import { ReferenceSet } from '../local/reference_set';
22+
import { TargetData, TargetPurpose } from '../local/target_data';
2323
import {
2424
documentKeySet,
2525
DocumentKeySet,
@@ -217,19 +217,19 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
217217
this.sharedClientState.addLocalQueryTarget(targetId);
218218
viewSnapshot = queryView.view.computeInitialSnapshot();
219219
} else {
220-
const queryData = await this.localStore.allocateTarget(query.toTarget());
220+
const targetData = await this.localStore.allocateTarget(query.toTarget());
221221

222222
const status = this.sharedClientState.addLocalQueryTarget(
223-
queryData.targetId
223+
targetData.targetId
224224
);
225-
targetId = queryData.targetId;
225+
targetId = targetData.targetId;
226226
viewSnapshot = await this.initializeViewAndComputeSnapshot(
227227
query,
228228
targetId,
229229
status === 'current'
230230
);
231231
if (this.isPrimary) {
232-
this.remoteStore.listen(queryData);
232+
this.remoteStore.listen(targetData);
233233
}
234234
}
235235

@@ -329,7 +329,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
329329

330330
if (!targetRemainsActive) {
331331
await this.localStore
332-
.releaseTarget(queryView.targetId, /*keepPersistedQueryData=*/ false)
332+
.releaseTarget(queryView.targetId, /*keepPersistedTargetData=*/ false)
333333
.then(() => {
334334
this.sharedClientState.clearQueryState(queryView.targetId);
335335
this.remoteStore.unlisten(queryView.targetId);
@@ -341,7 +341,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
341341
this.removeAndCleanupTarget(queryView.targetId);
342342
await this.localStore.releaseTarget(
343343
queryView.targetId,
344-
/*keepPersistedQueryData=*/ true
344+
/*keepPersistedTargetData=*/ true
345345
);
346346
}
347347
}
@@ -513,7 +513,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
513513
return this.applyRemoteEvent(event);
514514
} else {
515515
await this.localStore
516-
.releaseTarget(targetId, /* keepPersistedQueryData */ false)
516+
.releaseTarget(targetId, /* keepPersistedTargetData */ false)
517517
.then(() => this.removeAndCleanupTarget(targetId, err))
518518
.catch(ignoreIfPrimaryLeaseLoss);
519519
}
@@ -775,10 +775,10 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
775775
const query = Query.atPath(key.path);
776776
this.limboResolutionsByTarget[limboTargetId] = new LimboResolution(key);
777777
this.remoteStore.listen(
778-
new QueryData(
778+
new TargetData(
779779
query.toTarget(),
780780
limboTargetId,
781-
QueryPurpose.LimboResolution,
781+
TargetPurpose.LimboResolution,
782782
ListenSequence.INVALID
783783
)
784784
);
@@ -904,8 +904,8 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
904904
const activeQueries = await this.synchronizeQueryViewsAndRaiseSnapshots(
905905
activeTargets.toArray()
906906
);
907-
for (const queryData of activeQueries) {
908-
this.remoteStore.listen(queryData);
907+
for (const targetData of activeQueries) {
908+
this.remoteStore.listen(targetData);
909909
}
910910
} else if (isPrimary === false && this.isPrimary !== false) {
911911
this.isPrimary = false;
@@ -921,7 +921,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
921921
this.removeAndCleanupTarget(targetId);
922922
return this.localStore.releaseTarget(
923923
targetId,
924-
/*keepPersistedQueryData=*/ true
924+
/*keepPersistedTargetData=*/ true
925925
);
926926
});
927927
}
@@ -955,11 +955,11 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
955955
// PORTING NOTE: Multi-tab only.
956956
private async synchronizeQueryViewsAndRaiseSnapshots(
957957
targets: TargetId[]
958-
): Promise<QueryData[]> {
959-
const activeQueries: QueryData[] = [];
958+
): Promise<TargetData[]> {
959+
const activeQueries: TargetData[] = [];
960960
const newViewSnapshots: ViewSnapshot[] = [];
961961
for (const targetId of targets) {
962-
let queryData: QueryData;
962+
let targetData: TargetData;
963963
const queries = this.queriesByTarget[targetId];
964964

965965
if (queries && queries.length !== 0) {
@@ -969,9 +969,11 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
969969
// state (the list of syncedDocuments may have gotten out of sync).
970970
await this.localStore.releaseTarget(
971971
targetId,
972-
/*keepPersistedQueryData=*/ true
972+
/*keepPersistedTargetData=*/ true
973+
);
974+
targetData = await this.localStore.allocateTarget(
975+
queries[0].toTarget()
973976
);
974-
queryData = await this.localStore.allocateTarget(queries[0].toTarget());
975977

976978
for (const query of queries) {
977979
const queryView = this.queryViewsByQuery.get(query);
@@ -993,15 +995,15 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
993995
// allocate the target in LocalStore and initialize a new View.
994996
const target = await this.localStore.getTarget(targetId);
995997
assert(!!target, `Target for id ${targetId} not found`);
996-
queryData = await this.localStore.allocateTarget(target!);
998+
targetData = await this.localStore.allocateTarget(target!);
997999
await this.initializeViewAndComputeSnapshot(
9981000
this.synthesizeTargetToQuery(target!),
9991001
targetId,
10001002
/*current=*/ false
10011003
);
10021004
}
10031005

1004-
activeQueries.push(queryData!);
1006+
activeQueries.push(targetData!);
10051007
}
10061008

10071009
this.syncEngineListener!.onWatchChange(newViewSnapshots);
@@ -1068,7 +1070,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
10681070
case 'rejected': {
10691071
await this.localStore.releaseTarget(
10701072
targetId,
1071-
/* keepPersistedQueryData */ true
1073+
/* keepPersistedTargetData */ true
10721074
);
10731075
this.removeAndCleanupTarget(targetId, error);
10741076
break;
@@ -1095,13 +1097,13 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
10951097
);
10961098
const target = await this.localStore.getTarget(targetId);
10971099
assert(!!target, `Query data for active target ${targetId} not found`);
1098-
const queryData = await this.localStore.allocateTarget(target!);
1100+
const targetData = await this.localStore.allocateTarget(target!);
10991101
await this.initializeViewAndComputeSnapshot(
11001102
this.synthesizeTargetToQuery(target!),
1101-
queryData.targetId,
1103+
targetData.targetId,
11021104
/*current=*/ false
11031105
);
1104-
this.remoteStore.listen(queryData);
1106+
this.remoteStore.listen(targetData);
11051107
}
11061108

11071109
for (const targetId of removed) {
@@ -1113,7 +1115,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
11131115

11141116
// Release queries that are still active.
11151117
await this.localStore
1116-
.releaseTarget(targetId, /* keepPersistedQueryData */ false)
1118+
.releaseTarget(targetId, /* keepPersistedTargetData */ false)
11171119
.then(() => {
11181120
this.remoteStore.unlisten(targetId);
11191121
this.removeAndCleanupTarget(targetId);

packages/firestore/src/core/target_id_generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class TargetIdGenerator {
8181
this.nextId = targetId;
8282
}
8383

84-
static forQueryCache(): TargetIdGenerator {
84+
static forTargetCache(): TargetIdGenerator {
8585
// We seed the query cache generator to return '2' as its first ID, as there
8686
// is no differentiation in the protocol layer between an unset number and
8787
// the number '0'. If we were to sent a target with target ID '0', the

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ import {
3434
IndexedDbMutationQueue,
3535
mutationQueuesContainKey
3636
} from './indexeddb_mutation_queue';
37-
import {
38-
documentTargetStore,
39-
getHighestListenSequenceNumber,
40-
IndexedDbQueryCache
41-
} from './indexeddb_query_cache';
4237
import { IndexedDbRemoteDocumentCache } from './indexeddb_remote_document_cache';
4338
import {
4439
ALL_STORES,
@@ -51,6 +46,11 @@ import {
5146
SCHEMA_VERSION,
5247
SchemaConverter
5348
} from './indexeddb_schema';
49+
import {
50+
documentTargetStore,
51+
getHighestListenSequenceNumber,
52+
IndexedDbTargetCache
53+
} from './indexeddb_target_cache';
5454
import { LocalSerializer } from './local_serializer';
5555
import {
5656
ActiveTargets,
@@ -67,9 +67,9 @@ import {
6767
ReferenceDelegate
6868
} from './persistence';
6969
import { PersistencePromise } from './persistence_promise';
70-
import { QueryData } from './query_data';
7170
import { ReferenceSet } from './reference_set';
7271
import { ClientId } from './shared_client_state';
72+
import { TargetData } from './target_data';
7373
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';
7474

7575
const LOG_TAG = 'IndexedDbPersistence';
@@ -251,7 +251,7 @@ export class IndexedDbPersistence implements Persistence {
251251
/** A listener to notify on primary state changes. */
252252
private primaryStateListener: PrimaryStateListener = _ => Promise.resolve();
253253

254-
private readonly queryCache: IndexedDbQueryCache;
254+
private readonly targetCache: IndexedDbTargetCache;
255255
private readonly indexManager: IndexedDbIndexManager;
256256
private readonly remoteDocumentCache: IndexedDbRemoteDocumentCache;
257257
private readonly webStorage: Storage;
@@ -271,7 +271,7 @@ export class IndexedDbPersistence implements Persistence {
271271
this.dbName = persistenceKey + IndexedDbPersistence.MAIN_DATABASE;
272272
this.serializer = new LocalSerializer(serializer);
273273
this.document = platform.document;
274-
this.queryCache = new IndexedDbQueryCache(
274+
this.targetCache = new IndexedDbTargetCache(
275275
this.referenceDelegate,
276276
this.serializer
277277
);
@@ -716,12 +716,12 @@ export class IndexedDbPersistence implements Persistence {
716716
);
717717
}
718718

719-
getQueryCache(): IndexedDbQueryCache {
719+
getTargetCache(): IndexedDbTargetCache {
720720
assert(
721721
this.started,
722-
'Cannot initialize QueryCache before persistence is started.'
722+
'Cannot initialize TargetCache before persistence is started.'
723723
);
724-
return this.queryCache;
724+
return this.targetCache;
725725
}
726726

727727
getRemoteDocumentCache(): IndexedDbRemoteDocumentCache {
@@ -1113,7 +1113,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
11131113
txn: PersistenceTransaction
11141114
): PersistencePromise<number> {
11151115
const docCountPromise = this.orphanedDocmentCount(txn);
1116-
const targetCountPromise = this.db.getQueryCache().getQueryCount(txn);
1116+
const targetCountPromise = this.db.getTargetCache().getTargetCount(txn);
11171117
return targetCountPromise.next(targetCount =>
11181118
docCountPromise.next(docCount => targetCount + docCount)
11191119
);
@@ -1130,9 +1130,9 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
11301130

11311131
forEachTarget(
11321132
txn: PersistenceTransaction,
1133-
f: (q: QueryData) => void
1133+
f: (q: TargetData) => void
11341134
): PersistencePromise<void> {
1135-
return this.db.getQueryCache().forEachTarget(txn, f);
1135+
return this.db.getTargetCache().forEachTarget(txn, f);
11361136
}
11371137

11381138
forEachOrphanedDocumentSequenceNumber(
@@ -1168,7 +1168,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
11681168
activeTargetIds: ActiveTargets
11691169
): PersistencePromise<number> {
11701170
return this.db
1171-
.getQueryCache()
1171+
.getTargetCache()
11721172
.removeTargets(txn, upperBound, activeTargetIds);
11731173
}
11741174

@@ -1234,10 +1234,10 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
12341234

12351235
removeTarget(
12361236
txn: PersistenceTransaction,
1237-
queryData: QueryData
1237+
targetData: TargetData
12381238
): PersistencePromise<void> {
1239-
const updated = queryData.withSequenceNumber(txn.currentSequenceNumber);
1240-
return this.db.getQueryCache().updateQueryData(txn, updated);
1239+
const updated = targetData.withSequenceNumber(txn.currentSequenceNumber);
1240+
return this.db.getTargetCache().updateTargetData(txn, updated);
12411241
}
12421242

12431243
updateLimboDocument(

packages/firestore/src/local/indexeddb_schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { SnapshotVersion } from '../core/snapshot_version';
2424
import { BATCHID_UNKNOWN } from '../model/mutation_batch';
2525
import { decode, encode, EncodedResourcePath } from './encoded_resource_path';
2626
import { removeMutationBatch } from './indexeddb_mutation_queue';
27-
import { getHighestListenSequenceNumber } from './indexeddb_query_cache';
27+
import { getHighestListenSequenceNumber } from './indexeddb_target_cache';
2828
import { dbDocumentSize } from './indexeddb_remote_document_cache';
2929
import { LocalSerializer } from './local_serializer';
3030
import { MemoryCollectionParentIndex } from './memory_index_manager';

0 commit comments

Comments
 (0)