Skip to content

Commit ce908d8

Browse files
committed
Leave private methods out.
1 parent cd85d1a commit ce908d8

File tree

1 file changed

+61
-92
lines changed

1 file changed

+61
-92
lines changed

packages/firestore/src/core/sync_engine.ts

+61-92
Original file line numberDiff line numberDiff line change
@@ -211,55 +211,12 @@ export interface SyncEngine extends RemoteSyncer {
211211
*/
212212
registerPendingWritesCallback(callback: Deferred<void>): Promise<void>;
213213

214-
/**
215-
* Triggers the callbacks that are waiting for this batch id to get acknowledged by server,
216-
* if there are any.
217-
*/
218-
triggerPendingWritesCallbacks(batchId: BatchId): void;
219-
220-
/** Reject all outstanding callbacks waiting for pending writes to complete. */
221-
rejectOutstandingPendingWritesCallbacks(errorMessage: string): void;
222-
223-
addMutationCallback(batchId: BatchId, callback: Deferred<void>): void;
224-
225-
/**
226-
* Resolves or rejects the user callback for the given batch and then discards
227-
* it.
228-
*/
229-
processUserCallback(batchId: BatchId, error: Error | null): void;
230-
231-
removeAndCleanupTarget(targetId: number, error: Error | null): void;
232-
233-
removeLimboTarget(key: DocumentKey): void;
234-
235-
updateTrackedLimbos(
236-
targetId: TargetId,
237-
limboChanges: LimboDocumentChange[]
238-
): void;
239-
240214
trackLimboChange(limboChange: AddedLimboDocument): void;
241215

242-
/**
243-
* Starts listens for documents in limbo that are enqueued for resolution,
244-
* subject to a maximum number of concurrent resolutions.
245-
*
246-
* Without bounding the number of concurrent resolutions, the server can fail
247-
* with "resource exhausted" errors which can lead to pathological client
248-
* behavior as seen in https://github.com/firebase/firebase-js-sdk/issues/2683.
249-
*/
250-
pumpEnqueuedLimboResolutions(): void;
251-
252216
activeLimboDocumentResolutions(): SortedMap<DocumentKey, TargetId>;
253217

254218
enqueuedLimboDocumentResolutions(): DocumentKey[];
255219

256-
emitNewSnapsAndNotifyLocalStore(
257-
changes: MaybeDocumentMap,
258-
remoteEvent?: RemoteEvent
259-
): Promise<void>;
260-
261-
assertSubscribed(fnName: string): void;
262-
263220
handleCredentialChange(user: User): Promise<void>;
264221

265222
enableNetwork(): Promise<void>;
@@ -691,15 +648,20 @@ class SyncEngineImpl implements SyncEngine {
691648
}
692649
}
693650

694-
triggerPendingWritesCallbacks(batchId: BatchId): void {
651+
/**
652+
* Triggers the callbacks that are waiting for this batch id to get acknowledged by server,
653+
* if there are any.
654+
*/
655+
private triggerPendingWritesCallbacks(batchId: BatchId): void {
695656
(this.pendingWritesCallbacks.get(batchId) || []).forEach(callback => {
696657
callback.resolve();
697658
});
698659

699660
this.pendingWritesCallbacks.delete(batchId);
700661
}
701662

702-
rejectOutstandingPendingWritesCallbacks(errorMessage: string): void {
663+
/** Reject all outstanding callbacks waiting for pending writes to complete. */
664+
private rejectOutstandingPendingWritesCallbacks(errorMessage: string): void {
703665
this.pendingWritesCallbacks.forEach(callbacks => {
704666
callbacks.forEach(callback => {
705667
callback.reject(new FirestoreError(Code.CANCELLED, errorMessage));
@@ -709,7 +671,10 @@ class SyncEngineImpl implements SyncEngine {
709671
this.pendingWritesCallbacks.clear();
710672
}
711673

712-
addMutationCallback(batchId: BatchId, callback: Deferred<void>): void {
674+
private addMutationCallback(
675+
batchId: BatchId,
676+
callback: Deferred<void>
677+
): void {
713678
let newCallbacks = this.mutationUserCallbacks[this.currentUser.toKey()];
714679
if (!newCallbacks) {
715680
newCallbacks = new SortedMap<BatchId, Deferred<void>>(
@@ -720,7 +685,11 @@ class SyncEngineImpl implements SyncEngine {
720685
this.mutationUserCallbacks[this.currentUser.toKey()] = newCallbacks;
721686
}
722687

723-
processUserCallback(batchId: BatchId, error: Error | null): void {
688+
/**
689+
* Resolves or rejects the user callback for the given batch and then discards
690+
* it.
691+
*/
692+
protected processUserCallback(batchId: BatchId, error: Error | null): void {
724693
let newCallbacks = this.mutationUserCallbacks[this.currentUser.toKey()];
725694

726695
// NOTE: Mutations restored from persistence won't have callbacks, so it's
@@ -743,7 +712,10 @@ class SyncEngineImpl implements SyncEngine {
743712
}
744713
}
745714

746-
removeAndCleanupTarget(targetId: number, error: Error | null = null): void {
715+
protected removeAndCleanupTarget(
716+
targetId: number,
717+
error: Error | null = null
718+
): void {
747719
this.sharedClientState.removeLocalQueryTarget(targetId);
748720

749721
debugAssert(
@@ -773,7 +745,7 @@ class SyncEngineImpl implements SyncEngine {
773745
}
774746
}
775747

776-
removeLimboTarget(key: DocumentKey): void {
748+
private removeLimboTarget(key: DocumentKey): void {
777749
// It's possible that the target already got removed because the query failed. In that case,
778750
// the key won't exist in `limboTargetsByKey`. Only do the cleanup if we still have the target.
779751
const limboTargetId = this.activeLimboTargetsByKey.get(key);
@@ -788,7 +760,7 @@ class SyncEngineImpl implements SyncEngine {
788760
this.pumpEnqueuedLimboResolutions();
789761
}
790762

791-
updateTrackedLimbos(
763+
protected updateTrackedLimbos(
792764
targetId: TargetId,
793765
limboChanges: LimboDocumentChange[]
794766
): void {
@@ -812,7 +784,7 @@ class SyncEngineImpl implements SyncEngine {
812784
}
813785
}
814786

815-
trackLimboChange(limboChange: AddedLimboDocument): void {
787+
private trackLimboChange(limboChange: AddedLimboDocument): void {
816788
const key = limboChange.key;
817789
if (!this.activeLimboTargetsByKey.get(key)) {
818790
logDebug(LOG_TAG, 'New document in limbo: ' + key);
@@ -821,7 +793,15 @@ class SyncEngineImpl implements SyncEngine {
821793
}
822794
}
823795

824-
pumpEnqueuedLimboResolutions(): void {
796+
/**
797+
* Starts listens for documents in limbo that are enqueued for resolution,
798+
* subject to a maximum number of concurrent resolutions.
799+
*
800+
* Without bounding the number of concurrent resolutions, the server can fail
801+
* with "resource exhausted" errors which can lead to pathological client
802+
* behavior as seen in https://github.com/firebase/firebase-js-sdk/issues/2683.
803+
*/
804+
private pumpEnqueuedLimboResolutions(): void {
825805
while (
826806
this.enqueuedLimboResolutions.length > 0 &&
827807
this.activeLimboTargetsByKey.size < this.maxConcurrentLimboResolutions
@@ -857,7 +837,7 @@ class SyncEngineImpl implements SyncEngine {
857837
return this.enqueuedLimboResolutions;
858838
}
859839

860-
async emitNewSnapsAndNotifyLocalStore(
840+
protected async emitNewSnapsAndNotifyLocalStore(
861841
changes: MaybeDocumentMap,
862842
remoteEvent?: RemoteEvent
863843
): Promise<void> {
@@ -921,7 +901,7 @@ class SyncEngineImpl implements SyncEngine {
921901
await this.localStore.notifyLocalViewChanges(docChangesInAllViews);
922902
}
923903

924-
assertSubscribed(fnName: string): void {
904+
protected assertSubscribed(fnName: string): void {
925905
debugAssert(
926906
this.syncEngineListener !== null,
927907
'Trying to call ' + fnName + ' before calling subscribe().'
@@ -1006,41 +986,7 @@ export function newSyncEngine(
1006986
export interface MultiTabSyncEngine
1007987
extends SharedClientStateSyncer,
1008988
SyncEngine {
1009-
/**
1010-
* Reconcile the list of synced documents in an existing view with those
1011-
* from persistence.
1012-
*/
1013-
synchronizeViewAndComputeSnapshot(queryView: QueryView): Promise<ViewChange>;
1014-
1015989
applyPrimaryState(isPrimary: boolean): Promise<void>;
1016-
1017-
resetLimboDocuments(): void;
1018-
1019-
/**
1020-
* Reconcile the query views of the provided query targets with the state from
1021-
* persistence. Raises snapshots for any changes that affect the local
1022-
* client and returns the updated state of all target's query data.
1023-
*
1024-
* @param targets the list of targets with views that need to be recomputed
1025-
* @param transitionToPrimary `true` iff the tab transitions from a secondary
1026-
* tab to a primary tab
1027-
*/
1028-
synchronizeQueryViewsAndRaiseSnapshots(
1029-
targets: TargetId[],
1030-
transitionToPrimary: boolean
1031-
): Promise<TargetData[]>;
1032-
1033-
/**
1034-
* Creates a `Query` object from the specified `Target`. There is no way to
1035-
* obtain the original `Query`, so we synthesize a `Query` from the `Target`
1036-
* object.
1037-
*
1038-
* The synthesized result might be different from the original `Query`, but
1039-
* since the synthesized `Query` should return the same results as the
1040-
* original one (only the presentation of results might differ), the potential
1041-
* difference will not cause issues.
1042-
*/
1043-
synthesizeTargetToQuery(target: Target): Query;
1044990
}
1045991

1046992
/**
@@ -1090,7 +1036,11 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
10901036
return super.disableNetwork();
10911037
}
10921038

1093-
async synchronizeViewAndComputeSnapshot(
1039+
/**
1040+
* Reconcile the list of synced documents in an existing view with those
1041+
* from persistence.
1042+
*/
1043+
private async synchronizeViewAndComputeSnapshot(
10941044
queryView: QueryView
10951045
): Promise<ViewChange> {
10961046
const queryResult = await this.localStore.executeQuery(
@@ -1214,7 +1164,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12141164
}
12151165
}
12161166

1217-
resetLimboDocuments(): void {
1167+
private resetLimboDocuments(): void {
12181168
this.activeLimboResolutionsByTarget.forEach((_, targetId) => {
12191169
this.remoteStore.unlisten(targetId);
12201170
});
@@ -1225,7 +1175,16 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12251175
);
12261176
}
12271177

1228-
async synchronizeQueryViewsAndRaiseSnapshots(
1178+
/**
1179+
* Reconcile the query views of the provided query targets with the state from
1180+
* persistence. Raises snapshots for any changes that affect the local
1181+
* client and returns the updated state of all target's query data.
1182+
*
1183+
* @param targets the list of targets with views that need to be recomputed
1184+
* @param transitionToPrimary `true` iff the tab transitions from a secondary
1185+
* tab to a primary tab
1186+
*/
1187+
private async synchronizeQueryViewsAndRaiseSnapshots(
12291188
targets: TargetId[],
12301189
transitionToPrimary: boolean
12311190
): Promise<TargetData[]> {
@@ -1279,7 +1238,17 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12791238
return activeQueries;
12801239
}
12811240

1282-
synthesizeTargetToQuery(target: Target): Query {
1241+
/**
1242+
* Creates a `Query` object from the specified `Target`. There is no way to
1243+
* obtain the original `Query`, so we synthesize a `Query` from the `Target`
1244+
* object.
1245+
*
1246+
* The synthesized result might be different from the original `Query`, but
1247+
* since the synthesized `Query` should return the same results as the
1248+
* original one (only the presentation of results might differ), the potential
1249+
* difference will not cause issues.
1250+
*/
1251+
private synthesizeTargetToQuery(target: Target): Query {
12831252
return new Query(
12841253
target.path,
12851254
target.collectionGroup,

0 commit comments

Comments
 (0)