Skip to content

Commit 62e18b8

Browse files
committed
Persist the resume token on unlisten
1 parent 741377e commit 62e18b8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/firestore/src/local/local_store.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,22 @@ export class LocalStore {
698698
queryData != null,
699699
'Tried to release nonexistent query: ' + query
700700
);
701-
this.localViewReferences.removeReferencesForId(queryData!.targetId);
702-
delete this.targetIds[queryData!.targetId];
701+
702+
const targetId = queryData.targetId;
703+
const memoryQueryData = this.targetIds[targetId];
704+
705+
this.localViewReferences.removeReferencesForId(targetId);
706+
delete this.targetIds[targetId];
703707
if (this.garbageCollector.isEager) {
704-
return this.queryCache.removeQueryData(txn, queryData!);
708+
return this.queryCache.removeQueryData(txn, queryData);
709+
} else if (
710+
memoryQueryData.snapshotVersion > queryData.snapshotVersion
711+
) {
712+
// If we've been avoiding persisting the resumeToken (see
713+
// shouldPersistResumeToken for conditions and rationale) we need to
714+
// persist the token now because there will no longer be an
715+
// in-memory version to fall back on.
716+
return this.queryCache.updateQueryData(txn, memoryQueryData);
705717
} else {
706718
return PersistencePromise.resolve();
707719
}

0 commit comments

Comments
 (0)