Skip to content

Commit d927609

Browse files
committed
resolve comments
1 parent a0a933e commit d927609

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ async function executeQueryFromCache(
729729
const viewDocChanges = view.computeDocChanges(queryResult.documents);
730730
const viewChange = view.applyChanges(
731731
viewDocChanges,
732-
/* updateLimboDocuments= */ false
732+
/* limboResolutionEnabled= */ false
733733
);
734734
result.resolve(viewChange.snapshot!);
735735
} catch (e) {

packages/firestore/src/core/sync_engine_impl.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ async function initializeViewAndComputeSnapshot(
368368
);
369369
const viewChange = view.applyChanges(
370370
viewDocChanges,
371-
/* updateLimboDocuments= */ syncEngineImpl.isPrimaryClient,
371+
/* limboResolutionEnabled= */ syncEngineImpl.isPrimaryClient,
372372
synthesizedTargetChange
373373
);
374374
updateTrackedLimbos(syncEngineImpl, targetId, viewChange.limboChanges);
@@ -1081,13 +1081,13 @@ async function applyDocChanges(
10811081

10821082
const targetChange =
10831083
remoteEvent && remoteEvent.targetChanges.get(queryView.targetId);
1084-
const waitForRequeryResult =
1084+
const targetIsPendingReset =
10851085
remoteEvent && remoteEvent.targetMismatches.get(queryView.targetId) != null;
10861086
const viewChange = queryView.view.applyChanges(
10871087
viewDocChanges,
1088-
/* updateLimboDocuments= */ syncEngineImpl.isPrimaryClient,
1088+
/* limboResolutionEnabled= */ syncEngineImpl.isPrimaryClient,
10891089
targetChange,
1090-
waitForRequeryResult
1090+
targetIsPendingReset
10911091
);
10921092
updateTrackedLimbos(
10931093
syncEngineImpl,

packages/firestore/src/core/view.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,21 @@ export class View {
271271
* Updates the view with the given ViewDocumentChanges and optionally updates
272272
* limbo docs and sync state from the provided target change.
273273
* @param docChanges - The set of changes to make to the view's docs.
274-
* @param updateLimboDocuments - Whether to update limbo documents based on
274+
* @param limboResolutionEnabled - Whether to update limbo documents based on
275275
* this change.
276276
* @param targetChange - A target change to apply for computing limbo docs and
277277
* sync state.
278-
* @param waitForRequeryResult - Whether the target is pending to run a full
279-
* re-query due to existence filter mismatch.
278+
* @param targetIsPendingReset - Whether the target is pending to reset due to
279+
* existence filter mismatch. If not explicitly specified, it is treated
280+
* equivalently to false.
280281
* @returns A new ViewChange with the given docs, changes, and sync state.
281282
*/
282283
// PORTING NOTE: The iOS/Android clients always compute limbo document changes.
283284
applyChanges(
284285
docChanges: ViewDocumentChanges,
285-
updateLimboDocuments: boolean,
286+
limboResolutionEnabled: boolean,
286287
targetChange?: TargetChange,
287-
waitForRequeryResult?: boolean
288+
targetIsPendingReset?: boolean
288289
): ViewChange {
289290
debugAssert(
290291
!docChanges.needsRefill,
@@ -303,15 +304,17 @@ export class View {
303304
});
304305

305306
this.applyTargetChange(targetChange);
306-
const limboChanges = updateLimboDocuments
307-
? this.updateLimboDocuments(waitForRequeryResult ?? false)
308-
: [];
307+
308+
targetIsPendingReset = targetIsPendingReset ?? false;
309+
const limboChanges =
310+
limboResolutionEnabled && !targetIsPendingReset
311+
? this.updateLimboDocuments()
312+
: [];
309313

310314
// We are at synced state if there is no limbo docs are waiting to be resolved, view is current
311-
// with the backend, and the query is not pending for full re-query result due to existence
312-
// filter mismatch.
315+
// with the backend, and the query is not pending to reset due to existence filter mismatch.
313316
const synced =
314-
this.limboDocuments.size === 0 && this.current && !waitForRequeryResult;
317+
this.limboDocuments.size === 0 && this.current && !targetIsPendingReset;
315318

316319
const newSyncState = synced ? SyncState.Synced : SyncState.Local;
317320
const syncStateChanged = newSyncState !== this.syncState;
@@ -359,7 +362,7 @@ export class View {
359362
mutatedKeys: this.mutatedKeys,
360363
needsRefill: false
361364
},
362-
/* updateLimboDocuments= */ false
365+
/* limboResolutionEnabled= */ false
363366
);
364367
} else {
365368
// No effect, just return a no-op ViewChange.
@@ -412,11 +415,9 @@ export class View {
412415
}
413416
}
414417

415-
private updateLimboDocuments(
416-
waitForRequeryResult: boolean
417-
): LimboDocumentChange[] {
418+
private updateLimboDocuments(): LimboDocumentChange[] {
418419
// We can only determine limbo documents when we're in-sync with the server.
419-
if (waitForRequeryResult || !this.current) {
420+
if (!this.current) {
420421
return [];
421422
}
422423

@@ -469,7 +470,7 @@ export class View {
469470
this._syncedDocuments = queryResult.remoteKeys;
470471
this.limboDocuments = documentKeySet();
471472
const docChanges = this.computeDocChanges(queryResult.documents);
472-
return this.applyChanges(docChanges, /*updateLimboDocuments=*/ true);
473+
return this.applyChanges(docChanges, /* limboResolutionEnabled= */ true);
473474
}
474475

475476
/**

packages/firestore/test/unit/core/view.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,19 @@ describe('View', () => {
304304
let changes = view.computeDocChanges(documentUpdates(doc1));
305305
let viewChange = view.applyChanges(
306306
changes,
307-
/* updateLimboDocuments= */ true
307+
/* limboResolutionEnabled= */ true
308308
);
309309
expect(viewChange.snapshot!.fromCache).to.be.true;
310310

311311
// Add doc2 to generate a snapshot. Doc1 is still missing.
312312
changes = view.computeDocChanges(documentUpdates(doc2));
313-
viewChange = view.applyChanges(changes, /* updateLimboDocuments= */ true);
313+
viewChange = view.applyChanges(changes, /* limboResolutionEnabled= */ true);
314314
expect(viewChange.snapshot!.fromCache).to.be.true;
315315

316316
// Add doc2 to the backend's result set.
317317
viewChange = view.applyChanges(
318318
changes,
319-
/* updateLimboDocuments= */ true,
319+
/* limboResolutionEnabled= */ true,
320320
updateMapping(version(0), [doc2], [], [], /* current= */ true)
321321
);
322322
// We are CURRENT but doc1 is in limbo.
@@ -325,7 +325,7 @@ describe('View', () => {
325325
// Add doc1 to the backend's result set.
326326
viewChange = view.applyChanges(
327327
changes,
328-
/* updateLimboDocuments= */ true,
328+
/* limboResolutionEnabled= */ true,
329329
updateMapping(version(0), [doc1], [], [], /* current= */ true)
330330
);
331331
expect(viewChange.snapshot!.fromCache).to.be.false;

packages/firestore/test/unit/local/query_engine.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function genericQueryEngineTest(
253253
const viewDocChanges = view.computeDocChanges(docs);
254254
return view.applyChanges(
255255
viewDocChanges,
256-
/*updateLimboDocuments=*/ true
256+
/* limboResolutionEnabled= */ true
257257
).snapshot!.docs;
258258
});
259259
});

packages/firestore/test/unit/specs/limbo_spec.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ describeSpec('Limbo Documents:', [], () => {
928928
}
929929
);
930930

931-
// Reproduce the bug in b/238823695
931+
// Regression test for the bug in https://github.com/firebase/firebase-android-sdk/issues/5357
932932
specTest(
933933
'Limbo resolution should wait for full re-query result if there is an existence filter mismatch ',
934934
[],
@@ -949,8 +949,6 @@ describeSpec('Limbo Documents:', [], () => {
949949
.watchAcks(query1)
950950
// DocB is deleted in the next sync.
951951
.watchFilters([query1], [docA.key])
952-
// Bugged behavior: Missing watchCurrent here will move
953-
// all the docs to limbo unnecessarily.
954952
.watchCurrents(query1, 'resume-token-2000')
955953
.watchSnapshots(2000)
956954
.expectActiveTargets({
@@ -962,7 +960,7 @@ describeSpec('Limbo Documents:', [], () => {
962960
.watchAcksFull(query1, 3000, docA)
963961
// Only the deleted doc is moved to limbo after re-query result.
964962
.expectLimboDocs(docB.key)
965-
.ackLimbo(3000, deletedDoc('collection/b', 3000))
963+
.ackLimbo(3000, deletedDoc(docB.key.toString(), 3000))
966964
.expectLimboDocs()
967965
.expectEvents(query1, {
968966
removed: [docB]

0 commit comments

Comments
 (0)