Skip to content

Commit a4a7983

Browse files
committed
Persist the resume token on unlisten
1 parent 2cd9953 commit a4a7983

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
@@ -702,10 +702,22 @@ export class LocalStore {
702702
queryData != null,
703703
'Tried to release nonexistent query: ' + query
704704
);
705-
this.localViewReferences.removeReferencesForId(queryData!.targetId);
706-
delete this.targetIds[queryData!.targetId];
705+
706+
const targetId = queryData.targetId;
707+
const memoryQueryData = this.targetIds[targetId];
708+
709+
this.localViewReferences.removeReferencesForId(targetId);
710+
delete this.targetIds[targetId];
707711
if (this.garbageCollector.isEager) {
708-
return this.queryCache.removeQueryData(txn, queryData!);
712+
return this.queryCache.removeQueryData(txn, queryData);
713+
} else if (
714+
memoryQueryData.snapshotVersion > queryData.snapshotVersion
715+
) {
716+
// If we've been avoiding persisting the resumeToken (see
717+
// shouldPersistResumeToken for conditions and rationale) we need to
718+
// persist the token now because there will no longer be an
719+
// in-memory version to fall back on.
720+
return this.queryCache.updateQueryData(txn, memoryQueryData);
709721
} else {
710722
return PersistencePromise.resolve();
711723
}

0 commit comments

Comments
 (0)