Skip to content

Commit b6251e7

Browse files
Revert "Don't double save Query Data (#767)"
This reverts commit 8003a69.
1 parent df9fc6e commit b6251e7

File tree

1 file changed

+21
-3
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/local

1 file changed

+21
-3
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,29 @@ public void releaseQuery(Query query) {
574574
persistence.runTransaction(
575575
"Release query",
576576
() -> {
577-
QueryData queryData = getQueryData(query);
577+
QueryData queryData = queryCache.getQueryData(query);
578578
hardAssert(queryData != null, "Tried to release nonexistent query: %s", query);
579579

580+
int targetId = queryData.getTargetId();
581+
QueryData cachedQueryData = targetIds.get(targetId);
582+
583+
boolean needsUpdate = false;
584+
if (cachedQueryData.getSnapshotVersion().compareTo(queryData.getSnapshotVersion()) > 0) {
585+
// If we've been avoiding persisting the resumeToken (see shouldPersistQueryData for
586+
// conditions and rationale) we need to persist the token now because there will no
587+
// longer be an in-memory version to fall back on.
588+
needsUpdate = true;
589+
} else if (!cachedQueryData
590+
.getLastLimboFreeSnapshotVersion()
591+
.equals(queryData.getLastLimboFreeSnapshotVersion())) {
592+
needsUpdate = true;
593+
}
594+
595+
if (needsUpdate) {
596+
queryData = cachedQueryData;
597+
queryCache.updateQueryData(queryData);
598+
}
599+
580600
// References for documents sent via Watch are automatically removed when we delete a
581601
// query's target data from the reference delegate. Since this does not remove references
582602
// for locally mutated documents, we have to remove the target associations for these
@@ -586,8 +606,6 @@ public void releaseQuery(Query query) {
586606
for (DocumentKey key : removedReferences) {
587607
persistence.getReferenceDelegate().removeReference(key);
588608
}
589-
590-
// Note: This also updates the query cache
591609
persistence.getReferenceDelegate().removeTarget(queryData);
592610
targetIds.remove(queryData.getTargetId());
593611
});

0 commit comments

Comments
 (0)