@@ -558,7 +558,13 @@ public void releaseQuery(Query query) {
558
558
queryCache .updateQueryData (queryData );
559
559
}
560
560
561
- localViewReferences .removeReferencesForId (queryData .getTargetId ());
561
+ // We remove both locally edited documents and documents that are associated via the query
562
+ // cache.
563
+ ImmutableSortedSet <DocumentKey > removedReferences =
564
+ localViewReferences .removeReferencesForId (queryData .getTargetId ());
565
+ for (DocumentKey key : removedReferences ) {
566
+ persistence .getReferenceDelegate ().removeReference (key );
567
+ }
562
568
persistence .getReferenceDelegate ().removeTarget (queryData );
563
569
targetIds .remove (queryData .getTargetId ());
564
570
@@ -622,7 +628,7 @@ private Set<DocumentKey> releaseBatchResults(List<MutationBatchResult> batchResu
622
628
ArrayList <MutationBatch > batches = new ArrayList <>(batchResults .size ());
623
629
// TODO: Call queryEngine.handleDocumentChange() as appropriate.
624
630
for (MutationBatchResult batchResult : batchResults ) {
625
- applyBatchResult (batchResult );
631
+ applyWriteToRemoteDocuments (batchResult );
626
632
batches .add (batchResult .getBatch ());
627
633
}
628
634
@@ -647,7 +653,7 @@ private Set<DocumentKey> removeMutationBatches(List<MutationBatch> batches) {
647
653
return affectedDocs ;
648
654
}
649
655
650
- private void applyBatchResult (MutationBatchResult batchResult ) {
656
+ private void applyWriteToRemoteDocuments (MutationBatchResult batchResult ) {
651
657
MutationBatch batch = batchResult .getBatch ();
652
658
Set <DocumentKey > docKeys = batch .getKeys ();
653
659
for (DocumentKey docKey : docKeys ) {
0 commit comments