Skip to content

Don't double save Query Data #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -574,29 +574,9 @@ public void releaseQuery(Query query) {
persistence.runTransaction(
"Release query",
() -> {
QueryData queryData = queryCache.getQueryData(query);
QueryData queryData = getQueryData(query);
hardAssert(queryData != null, "Tried to release nonexistent query: %s", query);

int targetId = queryData.getTargetId();
QueryData cachedQueryData = targetIds.get(targetId);

boolean needsUpdate = false;
if (cachedQueryData.getSnapshotVersion().compareTo(queryData.getSnapshotVersion()) > 0) {
// If we've been avoiding persisting the resumeToken (see shouldPersistQueryData for
// conditions and rationale) we need to persist the token now because there will no
// longer be an in-memory version to fall back on.
needsUpdate = true;
} else if (!cachedQueryData
.getLastLimboFreeSnapshotVersion()
.equals(queryData.getLastLimboFreeSnapshotVersion())) {
needsUpdate = true;
}

if (needsUpdate) {
queryData = cachedQueryData;
queryCache.updateQueryData(queryData);
}

// References for documents sent via Watch are automatically removed when we delete a
// query's target data from the reference delegate. Since this does not remove references
// for locally mutated documents, we have to remove the target associations for these
Expand All @@ -606,6 +586,8 @@ public void releaseQuery(Query query) {
for (DocumentKey key : removedReferences) {
persistence.getReferenceDelegate().removeReference(key);
}

// Note: This also updates the query cache
persistence.getReferenceDelegate().removeTarget(queryData);
targetIds.remove(queryData.getTargetId());
});
Expand Down