Skip to content

Commit adb338b

Browse files
authored
Merge 9189965 into 8a7621b
2 parents 8a7621b + 9189965 commit adb338b

File tree

5 files changed

+426
-19
lines changed

5 files changed

+426
-19
lines changed

firebase-firestore/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [fixed] Fixed an issue in the local cache synchronization logic where all locally-cached documents that matched a resumed query would be unnecessarily re-downloaded; with the fix it now only downloads the documents that are known to be out-of-sync. [#5506](//github.com/firebase/firebase-android-sdk/pull/5506)
23

34

45
# 24.9.1

firebase-firestore/src/main/java/com/google/firebase/firestore/core/SyncEngine.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,13 @@ private void emitNewSnapsAndNotifyLocalStore(
653653
}
654654
TargetChange targetChange =
655655
remoteEvent == null ? null : remoteEvent.getTargetChanges().get(queryView.getTargetId());
656-
ViewChange viewChange = queryView.getView().applyChanges(viewDocChanges, targetChange);
656+
657+
boolean targetIsPendingReset =
658+
remoteEvent != null
659+
&& remoteEvent.getTargetMismatches().get(queryView.getTargetId()) != null;
660+
661+
ViewChange viewChange =
662+
queryView.getView().applyChanges(viewDocChanges, targetChange, targetIsPendingReset);
657663
updateTrackedLimboDocuments(viewChange.getLimboChanges(), queryView.getTargetId());
658664

659665
if (viewChange.getSnapshot() != null) {

firebase-firestore/src/main/java/com/google/firebase/firestore/core/View.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,21 @@ public ViewChange applyChanges(DocumentChanges docChanges) {
275275
* @return A new ViewChange with the given docs, changes, and sync state.
276276
*/
277277
public ViewChange applyChanges(DocumentChanges docChanges, TargetChange targetChange) {
278+
return applyChanges(docChanges, targetChange, false);
279+
}
280+
281+
/**
282+
* Updates the view with the given ViewDocumentChanges and updates limbo docs and sync state from
283+
* the given (optional) target change.
284+
*
285+
* @param docChanges The set of changes to make to the view's docs.
286+
* @param targetChange A target change to apply for computing limbo docs and sync state.
287+
* @param targetIsPendingReset - Whether the target is pending to reset due to existence filter
288+
* mismatch. If not explicitly specified, it is treated equivalently to `false`.
289+
* @return A new ViewChange with the given docs, changes, and sync state.
290+
*/
291+
public ViewChange applyChanges(
292+
DocumentChanges docChanges, TargetChange targetChange, boolean targetIsPendingReset) {
278293
hardAssert(!docChanges.needsRefill, "Cannot apply changes that need a refill");
279294

280295
DocumentSet oldDocumentSet = documentSet;
@@ -293,8 +308,12 @@ public ViewChange applyChanges(DocumentChanges docChanges, TargetChange targetCh
293308
return query.comparator().compare(o1.getDocument(), o2.getDocument());
294309
});
295310
applyTargetChange(targetChange);
296-
List<LimboDocumentChange> limboDocumentChanges = updateLimboDocuments();
297-
boolean synced = limboDocuments.size() == 0 && current;
311+
List<LimboDocumentChange> limboDocumentChanges =
312+
targetIsPendingReset ? Collections.emptyList() : updateLimboDocuments();
313+
314+
// We are at synced state if there is no limbo docs are waiting to be resolved, view is current
315+
// with the backend, and the query is not pending to reset due to existence filter mismatch.
316+
boolean synced = limboDocuments.size() == 0 && current && !targetIsPendingReset;
298317
SyncState newSyncState = synced ? SyncState.SYNCED : SyncState.LOCAL;
299318
boolean syncStatedChanged = newSyncState != syncState;
300319
syncState = newSyncState;

0 commit comments

Comments
 (0)