Skip to content

Rename QueryData and QueryCache to TargetData and TargetCache #2333

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 3 commits into from
Nov 5, 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
52 changes: 27 additions & 25 deletions packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import { User } from '../auth/user';
import { LocalStore } from '../local/local_store';
import { LocalViewChanges } from '../local/local_view_changes';
import { QueryData, QueryPurpose } from '../local/query_data';
import { ReferenceSet } from '../local/reference_set';
import { TargetData, TargetPurpose } from '../local/target_data';
import {
documentKeySet,
DocumentKeySet,
Expand Down Expand Up @@ -217,19 +217,19 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
this.sharedClientState.addLocalQueryTarget(targetId);
viewSnapshot = queryView.view.computeInitialSnapshot();
} else {
const queryData = await this.localStore.allocateTarget(query.toTarget());
const targetData = await this.localStore.allocateTarget(query.toTarget());

const status = this.sharedClientState.addLocalQueryTarget(
queryData.targetId
targetData.targetId
);
targetId = queryData.targetId;
targetId = targetData.targetId;
viewSnapshot = await this.initializeViewAndComputeSnapshot(
query,
targetId,
status === 'current'
);
if (this.isPrimary) {
this.remoteStore.listen(queryData);
this.remoteStore.listen(targetData);
}
}

Expand Down Expand Up @@ -329,7 +329,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {

if (!targetRemainsActive) {
await this.localStore
.releaseTarget(queryView.targetId, /*keepPersistedQueryData=*/ false)
.releaseTarget(queryView.targetId, /*keepPersistedTargetData=*/ false)
.then(() => {
this.sharedClientState.clearQueryState(queryView.targetId);
this.remoteStore.unlisten(queryView.targetId);
Expand All @@ -341,7 +341,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
this.removeAndCleanupTarget(queryView.targetId);
await this.localStore.releaseTarget(
queryView.targetId,
/*keepPersistedQueryData=*/ true
/*keepPersistedTargetData=*/ true
);
}
}
Expand Down Expand Up @@ -513,7 +513,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
return this.applyRemoteEvent(event);
} else {
await this.localStore
.releaseTarget(targetId, /* keepPersistedQueryData */ false)
.releaseTarget(targetId, /* keepPersistedTargetData */ false)
.then(() => this.removeAndCleanupTarget(targetId, err))
.catch(ignoreIfPrimaryLeaseLoss);
}
Expand Down Expand Up @@ -775,10 +775,10 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
const query = Query.atPath(key.path);
this.limboResolutionsByTarget[limboTargetId] = new LimboResolution(key);
this.remoteStore.listen(
new QueryData(
new TargetData(
query.toTarget(),
limboTargetId,
QueryPurpose.LimboResolution,
TargetPurpose.LimboResolution,
ListenSequence.INVALID
)
);
Expand Down Expand Up @@ -904,8 +904,8 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
const activeQueries = await this.synchronizeQueryViewsAndRaiseSnapshots(
activeTargets.toArray()
);
for (const queryData of activeQueries) {
this.remoteStore.listen(queryData);
for (const targetData of activeQueries) {
this.remoteStore.listen(targetData);
}
} else if (isPrimary === false && this.isPrimary !== false) {
this.isPrimary = false;
Expand All @@ -921,7 +921,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
this.removeAndCleanupTarget(targetId);
return this.localStore.releaseTarget(
targetId,
/*keepPersistedQueryData=*/ true
/*keepPersistedTargetData=*/ true
);
});
}
Expand Down Expand Up @@ -955,11 +955,11 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
// PORTING NOTE: Multi-tab only.
private async synchronizeQueryViewsAndRaiseSnapshots(
targets: TargetId[]
): Promise<QueryData[]> {
const activeQueries: QueryData[] = [];
): Promise<TargetData[]> {
const activeQueries: TargetData[] = [];
const newViewSnapshots: ViewSnapshot[] = [];
for (const targetId of targets) {
let queryData: QueryData;
let targetData: TargetData;
const queries = this.queriesByTarget[targetId];

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

for (const query of queries) {
const queryView = this.queryViewsByQuery.get(query);
Expand All @@ -993,15 +995,15 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
// allocate the target in LocalStore and initialize a new View.
const target = await this.localStore.getTarget(targetId);
assert(!!target, `Target for id ${targetId} not found`);
queryData = await this.localStore.allocateTarget(target!);
targetData = await this.localStore.allocateTarget(target!);
await this.initializeViewAndComputeSnapshot(
this.synthesizeTargetToQuery(target!),
targetId,
/*current=*/ false
);
}

activeQueries.push(queryData!);
activeQueries.push(targetData!);
}

this.syncEngineListener!.onWatchChange(newViewSnapshots);
Expand Down Expand Up @@ -1068,7 +1070,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
case 'rejected': {
await this.localStore.releaseTarget(
targetId,
/* keepPersistedQueryData */ true
/* keepPersistedTargetData */ true
);
this.removeAndCleanupTarget(targetId, error);
break;
Expand All @@ -1095,13 +1097,13 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
);
const target = await this.localStore.getTarget(targetId);
assert(!!target, `Query data for active target ${targetId} not found`);
const queryData = await this.localStore.allocateTarget(target!);
const targetData = await this.localStore.allocateTarget(target!);
await this.initializeViewAndComputeSnapshot(
this.synthesizeTargetToQuery(target!),
queryData.targetId,
targetData.targetId,
/*current=*/ false
);
this.remoteStore.listen(queryData);
this.remoteStore.listen(targetData);
}

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

// Release queries that are still active.
await this.localStore
.releaseTarget(targetId, /* keepPersistedQueryData */ false)
.releaseTarget(targetId, /* keepPersistedTargetData */ false)
.then(() => {
this.remoteStore.unlisten(targetId);
this.removeAndCleanupTarget(targetId);
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/target_id_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class TargetIdGenerator {
this.nextId = targetId;
}

static forQueryCache(): TargetIdGenerator {
static forTargetCache(): TargetIdGenerator {
// We seed the query cache generator to return '2' as its first ID, as there
// is no differentiation in the protocol layer between an unset number and
// the number '0'. If we were to sent a target with target ID '0', the
Expand Down
36 changes: 18 additions & 18 deletions packages/firestore/src/local/indexeddb_persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ import {
IndexedDbMutationQueue,
mutationQueuesContainKey
} from './indexeddb_mutation_queue';
import {
documentTargetStore,
getHighestListenSequenceNumber,
IndexedDbQueryCache
} from './indexeddb_query_cache';
import { IndexedDbRemoteDocumentCache } from './indexeddb_remote_document_cache';
import {
ALL_STORES,
Expand All @@ -51,6 +46,11 @@ import {
SCHEMA_VERSION,
SchemaConverter
} from './indexeddb_schema';
import {
documentTargetStore,
getHighestListenSequenceNumber,
IndexedDbTargetCache
} from './indexeddb_target_cache';
import { LocalSerializer } from './local_serializer';
import {
ActiveTargets,
Expand All @@ -67,9 +67,9 @@ import {
ReferenceDelegate
} from './persistence';
import { PersistencePromise } from './persistence_promise';
import { QueryData } from './query_data';
import { ReferenceSet } from './reference_set';
import { ClientId } from './shared_client_state';
import { TargetData } from './target_data';
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';

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

private readonly queryCache: IndexedDbQueryCache;
private readonly targetCache: IndexedDbTargetCache;
private readonly indexManager: IndexedDbIndexManager;
private readonly remoteDocumentCache: IndexedDbRemoteDocumentCache;
private readonly webStorage: Storage;
Expand All @@ -271,7 +271,7 @@ export class IndexedDbPersistence implements Persistence {
this.dbName = persistenceKey + IndexedDbPersistence.MAIN_DATABASE;
this.serializer = new LocalSerializer(serializer);
this.document = platform.document;
this.queryCache = new IndexedDbQueryCache(
this.targetCache = new IndexedDbTargetCache(
this.referenceDelegate,
this.serializer
);
Expand Down Expand Up @@ -716,12 +716,12 @@ export class IndexedDbPersistence implements Persistence {
);
}

getQueryCache(): IndexedDbQueryCache {
getTargetCache(): IndexedDbTargetCache {
assert(
this.started,
'Cannot initialize QueryCache before persistence is started.'
'Cannot initialize TargetCache before persistence is started.'
);
return this.queryCache;
return this.targetCache;
}

getRemoteDocumentCache(): IndexedDbRemoteDocumentCache {
Expand Down Expand Up @@ -1113,7 +1113,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
txn: PersistenceTransaction
): PersistencePromise<number> {
const docCountPromise = this.orphanedDocmentCount(txn);
const targetCountPromise = this.db.getQueryCache().getQueryCount(txn);
const targetCountPromise = this.db.getTargetCache().getTargetCount(txn);
return targetCountPromise.next(targetCount =>
docCountPromise.next(docCount => targetCount + docCount)
);
Expand All @@ -1130,9 +1130,9 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {

forEachTarget(
txn: PersistenceTransaction,
f: (q: QueryData) => void
f: (q: TargetData) => void
): PersistencePromise<void> {
return this.db.getQueryCache().forEachTarget(txn, f);
return this.db.getTargetCache().forEachTarget(txn, f);
}

forEachOrphanedDocumentSequenceNumber(
Expand Down Expand Up @@ -1168,7 +1168,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
activeTargetIds: ActiveTargets
): PersistencePromise<number> {
return this.db
.getQueryCache()
.getTargetCache()
.removeTargets(txn, upperBound, activeTargetIds);
}

Expand Down Expand Up @@ -1234,10 +1234,10 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {

removeTarget(
txn: PersistenceTransaction,
queryData: QueryData
targetData: TargetData
): PersistencePromise<void> {
const updated = queryData.withSequenceNumber(txn.currentSequenceNumber);
return this.db.getQueryCache().updateQueryData(txn, updated);
const updated = targetData.withSequenceNumber(txn.currentSequenceNumber);
return this.db.getTargetCache().updateTargetData(txn, updated);
}

updateLimboDocument(
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/local/indexeddb_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { SnapshotVersion } from '../core/snapshot_version';
import { BATCHID_UNKNOWN } from '../model/mutation_batch';
import { decode, encode, EncodedResourcePath } from './encoded_resource_path';
import { removeMutationBatch } from './indexeddb_mutation_queue';
import { getHighestListenSequenceNumber } from './indexeddb_query_cache';
import { getHighestListenSequenceNumber } from './indexeddb_target_cache';
import { dbDocumentSize } from './indexeddb_remote_document_cache';
import { LocalSerializer } from './local_serializer';
import { MemoryCollectionParentIndex } from './memory_index_manager';
Expand Down
Loading