Skip to content

Commit fd9de63

Browse files
committed
Revert "Relax individual document revert constraints"
This reverts commit 6ce8ed4.
1 parent 9bc9ba4 commit fd9de63

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

packages/firestore/src/local/local_store.ts

+34-7
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,40 @@ export class LocalStore {
458458
}
459459
);
460460

461+
let changedDocKeys = documentKeySet();
462+
remoteEvent.documentUpdates.forEach((key, doc) => {
463+
changedDocKeys = changedDocKeys.add(key);
464+
promises.push(
465+
documentBuffer.getEntry(txn, key).next(existingDoc => {
466+
// Make sure we don't apply an old document version to the remote
467+
// cache, though we make an exception for SnapshotVersion.MIN which
468+
// can happen for manufactured events (e.g. in the case of a limbo
469+
// document resolution failing).
470+
if (
471+
existingDoc == null ||
472+
doc.version.isEqual(SnapshotVersion.MIN) ||
473+
doc.version.compareTo(existingDoc.version) >= 0
474+
) {
475+
documentBuffer.addEntry(doc);
476+
} else {
477+
log.debug(
478+
LOG_TAG,
479+
'Ignoring outdated watch update for ',
480+
key,
481+
'. Current version:',
482+
existingDoc.version,
483+
' Watch version:',
484+
doc.version
485+
);
486+
}
487+
488+
// The document might be garbage because it was unreferenced by
489+
// everything. Make sure to mark it as garbage if it is...
490+
this.garbageCollector.addPotentialGarbageKey(key);
491+
})
492+
);
493+
});
494+
461495
// HACK: The only reason we allow a null snapshot version is so that we
462496
// can synthesize remote events when we get permission denied errors while
463497
// trying to resolve the state of a locally cached document that is in
@@ -477,13 +511,6 @@ export class LocalStore {
477511
);
478512
}
479513

480-
let changedDocKeys = documentKeySet();
481-
remoteEvent.documentUpdates.forEach((key, doc) => {
482-
changedDocKeys = changedDocKeys.add(key);
483-
documentBuffer.addEntry(doc);
484-
this.garbageCollector.addPotentialGarbageKey(key);
485-
});
486-
487514
let releasedWriteKeys: DocumentKeySet;
488515
return PersistencePromise.waitFor(promises)
489516
.next(() => this.releaseHeldBatchResults(txn, documentBuffer))

0 commit comments

Comments
 (0)