Skip to content

Commit 53e8fdb

Browse files
Revert "Remove newly redundant synced flag (#771)"
This reverts commit 934a88d.
1 parent 04d6dff commit 53e8fdb

File tree

13 files changed

+57
-24
lines changed

13 files changed

+57
-24
lines changed

firebase-firestore/ktx/src/test/java/com/google/firebase/firestore/TestUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public static QuerySnapshot querySnapshot(
117117
documentChanges,
118118
isFromCache,
119119
mutatedKeys,
120+
/* synced= */ false,
120121
/* didSyncStateChange= */ true,
121122
/* excludesMetadataChanges= */ false);
122123
return new QuerySnapshot(query(path), viewSnapshot, FIRESTORE);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public boolean onViewSnapshot(ViewSnapshot newSnapshot) {
8686
documentChanges,
8787
newSnapshot.isFromCache(),
8888
newSnapshot.getMutatedKeys(),
89+
newSnapshot.isSynced(),
8990
newSnapshot.didSyncStateChange(),
9091
/* excludesMetadataChanges= */ true);
9192
}
@@ -171,6 +172,7 @@ private void raiseInitialEvent(ViewSnapshot snapshot) {
171172
snapshot.getDocuments(),
172173
snapshot.getMutatedKeys(),
173174
snapshot.isFromCache(),
175+
snapshot.isSynced(),
174176
snapshot.excludesMetadataChanges());
175177
raisedInitialEvent = true;
176178
listener.onEvent(snapshot, null);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public ViewChange applyChanges(DocumentChanges docChanges, TargetChange targetCh
311311
viewChanges,
312312
fromCache,
313313
docChanges.mutatedKeys,
314+
synced,
314315
syncStatedChanged,
315316
/* excludesMetadataChanges= */ false);
316317
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public enum SyncState {
3737
private final List<DocumentViewChange> changes;
3838
private final boolean isFromCache;
3939
private final ImmutableSortedSet<DocumentKey> mutatedKeys;
40+
private final boolean synced;
4041
private final boolean didSyncStateChange;
4142
private boolean excludesMetadataChanges;
4243

@@ -47,6 +48,7 @@ public ViewSnapshot(
4748
List<DocumentViewChange> changes,
4849
boolean isFromCache,
4950
ImmutableSortedSet<DocumentKey> mutatedKeys,
51+
boolean synced,
5052
boolean didSyncStateChange,
5153
boolean excludesMetadataChanges) {
5254
this.query = query;
@@ -55,6 +57,7 @@ public ViewSnapshot(
5557
this.changes = changes;
5658
this.isFromCache = isFromCache;
5759
this.mutatedKeys = mutatedKeys;
60+
this.synced = synced;
5861
this.didSyncStateChange = didSyncStateChange;
5962
this.excludesMetadataChanges = excludesMetadataChanges;
6063
}
@@ -65,6 +68,7 @@ public static ViewSnapshot fromInitialDocuments(
6568
DocumentSet documents,
6669
ImmutableSortedSet<DocumentKey> mutatedKeys,
6770
boolean fromCache,
71+
boolean synced,
6872
boolean excludesMetadataChanges) {
6973
List<DocumentViewChange> viewChanges = new ArrayList<>();
7074
for (Document doc : documents) {
@@ -77,6 +81,7 @@ public static ViewSnapshot fromInitialDocuments(
7781
viewChanges,
7882
fromCache,
7983
mutatedKeys,
84+
synced,
8085
/* didSyncStateChange= */ true,
8186
excludesMetadataChanges);
8287
}
@@ -85,6 +90,10 @@ public Query getQuery() {
8590
return query;
8691
}
8792

93+
public boolean isSynced() {
94+
return synced;
95+
}
96+
8897
public DocumentSet getDocuments() {
8998
return documents;
9099
}
@@ -131,6 +140,9 @@ public final boolean equals(Object o) {
131140
if (isFromCache != that.isFromCache) {
132141
return false;
133142
}
143+
if (synced != that.synced) {
144+
return false;
145+
}
134146
if (didSyncStateChange != that.didSyncStateChange) {
135147
return false;
136148
}
@@ -160,6 +172,7 @@ public int hashCode() {
160172
result = 31 * result + changes.hashCode();
161173
result = 31 * result + mutatedKeys.hashCode();
162174
result = 31 * result + (isFromCache ? 1 : 0);
175+
result = 31 * result + (synced ? 1 : 0);
163176
result = 31 * result + (didSyncStateChange ? 1 : 0);
164177
result = 31 * result + (excludesMetadataChanges ? 1 : 0);
165178
return result;
@@ -179,6 +192,8 @@ public String toString() {
179192
+ isFromCache
180193
+ ", mutatedKeys="
181194
+ mutatedKeys.size()
195+
+ ", synced="
196+
+ synced
182197
+ ", didSyncStateChange="
183198
+ didSyncStateChange
184199
+ ", excludesMetadataChanges="

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public void notifyLocalViewChanges(List<LocalViewChanges> viewChanges) {
478478
}
479479
localViewReferences.removeReferences(removed, targetId);
480480

481-
if (!viewChange.isFromCache()) {
481+
if (viewChange.isSynced()) {
482482
QueryData queryData = targetIds.get(targetId);
483483
hardAssert(
484484
queryData != null,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ public static LocalViewChanges fromViewSnapshot(int targetId, ViewSnapshot snaps
4949
}
5050
}
5151

52-
return new LocalViewChanges(targetId, snapshot.isFromCache(), addedKeys, removedKeys);
52+
return new LocalViewChanges(targetId, snapshot.isSynced(), addedKeys, removedKeys);
5353
}
5454

5555
private final int targetId;
56-
private final boolean fromCache;
56+
private final boolean synced;
5757

5858
private final ImmutableSortedSet<DocumentKey> added;
5959
private final ImmutableSortedSet<DocumentKey> removed;
6060

6161
public LocalViewChanges(
6262
int targetId,
63-
boolean fromCache,
63+
boolean synced,
6464
ImmutableSortedSet<DocumentKey> added,
6565
ImmutableSortedSet<DocumentKey> removed) {
6666
this.targetId = targetId;
67-
this.fromCache = fromCache;
67+
this.synced = synced;
6868
this.added = added;
6969
this.removed = removed;
7070
}
@@ -73,8 +73,8 @@ public int getTargetId() {
7373
return targetId;
7474
}
7575

76-
public boolean isFromCache() {
77-
return fromCache;
76+
public boolean isSynced() {
77+
return synced;
7878
}
7979

8080
public ImmutableSortedSet<DocumentKey> getAdded() {

firebase-firestore/src/roboUtil/java/com/google/firebase/firestore/TestUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public static QuerySnapshot querySnapshot(
129129
documentChanges,
130130
isFromCache,
131131
mutatedKeys,
132+
/* synced= */ false,
132133
/* didSyncStateChange= */ true,
133134
/* excludesMetadataChanges= */ false);
134135
return new QuerySnapshot(query(path), viewSnapshot, FIRESTORE);

firebase-firestore/src/test/java/com/google/firebase/firestore/QuerySnapshotTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public void testIncludeMetadataChanges() {
125125
documentChanges,
126126
/*isFromCache=*/ false,
127127
/*mutatedKeys=*/ keySet(),
128+
/*isSynced=*/ true,
128129
/*didSyncStateChange=*/ true,
129130
/* excludesMetadataChanges= */ false);
130131

firebase-firestore/src/test/java/com/google/firebase/firestore/core/QueryListenerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public void testRaisesCollectionEvents() {
108108
asList(change1, change4),
109109
snap2.isFromCache(),
110110
snap2.getMutatedKeys(),
111+
/* synced= */ false,
111112
/* didSyncStateChange= */ true,
112113
/* excludesMetadataChanges= */ false);
113114
assertEquals(asList(snap2Prime), otherAccum);
@@ -265,6 +266,7 @@ public void testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChang
265266
asList(),
266267
snap4.isFromCache(),
267268
snap4.getMutatedKeys(),
269+
snap4.isSynced(),
268270
snap4.didSyncStateChange(),
269271
/* excludeMetadataChanges= */ true); // This test excludes document metadata changes
270272

@@ -306,6 +308,7 @@ public void testMetadataOnlyDocumentChangesAreFilteredOut() {
306308
asList(change3),
307309
snap2.isFromCache(),
308310
snap2.getMutatedKeys(),
311+
snap2.isSynced(),
309312
snap2.didSyncStateChange(),
310313
/* excludesMetadataChanges= */ true);
311314
assertEquals(
@@ -348,6 +351,7 @@ public void testWillWaitForSyncIfOnline() {
348351
asList(change1, change2),
349352
/* isFromCache= */ false,
350353
snap3.getMutatedKeys(),
354+
/* synced= */ true,
351355
/* didSyncStateChange= */ true,
352356
/* excludesMetadataChanges= */ true);
353357
assertEquals(asList(expectedSnapshot), events);
@@ -386,6 +390,7 @@ public void testWillRaiseInitialEventWhenGoingOffline() {
386390
asList(change1),
387391
/* isFromCache= */ true,
388392
snap1.getMutatedKeys(),
393+
snap1.isSynced(),
389394
/* didSyncStateChange= */ true,
390395
/* excludesMetadataChanges= */ true);
391396
ViewSnapshot expectedSnapshot2 =
@@ -396,6 +401,7 @@ public void testWillRaiseInitialEventWhenGoingOffline() {
396401
asList(change2),
397402
/* isFromCache= */ true,
398403
snap2.getMutatedKeys(),
404+
snap2.isSynced(),
399405
/* didSyncStateChange= */ false,
400406
/* excludesMetadataChanges= */ true);
401407
assertEquals(asList(expectedSnapshot1, expectedSnapshot2), events);
@@ -423,6 +429,7 @@ public void testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs() {
423429
asList(),
424430
/* isFromCache= */ true,
425431
snap1.getMutatedKeys(),
432+
snap1.isSynced(),
426433
/* didSyncStateChange= */ true,
427434
/* excludesMetadataChanges= */ true);
428435
assertEquals(asList(expectedSnapshot), events);
@@ -449,6 +456,7 @@ public void testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs() {
449456
asList(),
450457
/* isFromCache= */ true,
451458
snap1.getMutatedKeys(),
459+
snap1.isSynced(),
452460
/* didSyncStateChange= */ true,
453461
/* excludesMetadataChanges= */ true);
454462
assertEquals(asList(expectedSnapshot), events);
@@ -462,6 +470,7 @@ private ViewSnapshot applyExpectedMetadata(ViewSnapshot snap, MetadataChanges me
462470
snap.getChanges(),
463471
snap.isFromCache(),
464472
snap.getMutatedKeys(),
473+
snap.isSynced(),
465474
snap.didSyncStateChange(),
466475
MetadataChanges.EXCLUDE.equals(metadata));
467476
}

firebase-firestore/src/test/java/com/google/firebase/firestore/core/ViewSnapshotTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void testConstructor() {
4545
List<DocumentViewChange> changes =
4646
Arrays.asList(DocumentViewChange.create(Type.ADDED, doc("c/foo", 1, map())));
4747
ImmutableSortedSet<DocumentKey> mutatedKeys = keySet(key("c/foo"));
48+
boolean synced = true;
4849
boolean fromCache = true;
4950
boolean hasPendingWrites = true;
5051
boolean syncStateChanges = true;
@@ -58,6 +59,7 @@ public void testConstructor() {
5859
changes,
5960
fromCache,
6061
mutatedKeys,
62+
synced,
6163
syncStateChanges,
6264
excludesMetadataChanges);
6365

@@ -67,6 +69,7 @@ public void testConstructor() {
6769
assertEquals(changes, snapshot.getChanges());
6870
assertEquals(fromCache, snapshot.isFromCache());
6971
assertEquals(mutatedKeys, snapshot.getMutatedKeys());
72+
assertEquals(synced, snapshot.isSynced());
7073
assertEquals(hasPendingWrites, snapshot.hasPendingWrites());
7174
assertEquals(syncStateChanges, snapshot.didSyncStateChange());
7275
assertEquals(excludesMetadataChanges, snapshot.excludesMetadataChanges());

firebase-firestore/src/test/java/com/google/firebase/firestore/core/ViewTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public void testKeepsTrackOfLimboDocuments() {
302302
}
303303

304304
@Test
305-
public void testViewsWithLimboDocumentsAreMarkedFromCache() {
305+
public void testViewsWithLimboDocumentsAreNotMarkedSynced() {
306306
Query query = messageQuery();
307307
View view = new View(query, DocumentKey.emptyKeySet());
308308
Document doc1 = doc("rooms/eros/messages/0", 0, map());
@@ -311,20 +311,20 @@ public void testViewsWithLimboDocumentsAreMarkedFromCache() {
311311
// Doc1 is contained in the local view, but we are not yet CURRENT so it is expected that the
312312
// backend hasn't told us about all documents yet.
313313
ViewChange change = applyChanges(view, doc1);
314-
assertTrue(change.getSnapshot().isFromCache());
314+
assertFalse(change.getSnapshot().isSynced());
315315

316316
// Add doc2 to generate a snapshot. Doc1 is still missing.
317317
View.DocumentChanges viewDocChanges = view.computeDocChanges(docUpdates(doc2));
318318
change =
319319
view.applyChanges(
320320
viewDocChanges, targetChange(ByteString.EMPTY, true, asList(doc2), null, null));
321-
assertTrue(change.getSnapshot().isFromCache()); // We are CURRENT but doc1 is in limbo.
321+
assertFalse(change.getSnapshot().isSynced()); // We are CURRENT but doc1 is in limbo.
322322

323323
// Add doc1 to the backend's result set.
324324
change =
325325
view.applyChanges(
326326
viewDocChanges, targetChange(ByteString.EMPTY, true, asList(doc1), null, null));
327-
assertFalse(change.getSnapshot().isFromCache());
327+
assertTrue(change.getSnapshot().isSynced());
328328
}
329329

330330
@Test

firebase-firestore/src/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ private void notifyLocalViewChanges(LocalViewChanges changes) {
146146
localStore.notifyLocalViewChanges(asList(changes));
147147
}
148148

149-
private void udpateViews(int targetId, boolean fromCache) {
150-
notifyLocalViewChanges(viewChanges(targetId, fromCache, asList(), asList()));
149+
private void udpateViews(int targetId, boolean synced) {
150+
notifyLocalViewChanges(viewChanges(targetId, synced, asList(), asList()));
151151
}
152152

153153
private void acknowledgeMutation(long documentVersion, @Nullable Object transformResult) {
@@ -311,7 +311,7 @@ public void testHandlesSetMutationThenAckThenRelease() {
311311
allocateQuery(query);
312312

313313
writeMutation(setMutation("foo/bar", map("foo", "bar")));
314-
notifyLocalViewChanges(viewChanges(2, /* fromCache= */ false, asList("foo/bar"), emptyList()));
314+
notifyLocalViewChanges(viewChanges(2, /* synced= */ false, asList("foo/bar"), emptyList()));
315315

316316
assertChanged(doc("foo/bar", 0, map("foo", "bar"), Document.DocumentState.LOCAL_MUTATIONS));
317317
assertContains(doc("foo/bar", 0, map("foo", "bar"), Document.DocumentState.LOCAL_MUTATIONS));
@@ -832,15 +832,15 @@ public void testPinsDocumentsInTheLocalView() {
832832
assertContains(doc("foo/baz", 0, map("foo", "baz"), Document.DocumentState.LOCAL_MUTATIONS));
833833

834834
notifyLocalViewChanges(
835-
viewChanges(2, /* fromCache= */ false, asList("foo/bar", "foo/baz"), emptyList()));
835+
viewChanges(2, /* synced= */ false, asList("foo/bar", "foo/baz"), emptyList()));
836836
applyRemoteEvent(updateRemoteEvent(doc("foo/bar", 1, map("foo", "bar")), none, two));
837837
applyRemoteEvent(updateRemoteEvent(doc("foo/baz", 2, map("foo", "baz")), two, none));
838838
acknowledgeMutation(2);
839839
assertContains(doc("foo/bar", 1, map("foo", "bar")));
840840
assertContains(doc("foo/baz", 2, map("foo", "baz")));
841841

842842
notifyLocalViewChanges(
843-
viewChanges(2, /* fromCache= */ false, emptyList(), asList("foo/bar", "foo/baz")));
843+
viewChanges(2, /* synced= */ false, emptyList(), asList("foo/bar", "foo/baz")));
844844
releaseQuery(query);
845845

846846
assertNotContains("foo/bar");
@@ -1062,7 +1062,7 @@ public void testUsesTargetMappingToExecuteQueries() {
10621062
asList(targetId),
10631063
emptyList()));
10641064
applyRemoteEvent(noChangeEvent(targetId, 10));
1065-
udpateViews(targetId, /* fromCache= */ false);
1065+
udpateViews(targetId, /* synced= */ true);
10661066

10671067
// Execute the query again, this time verifying that we only read the two documents that match
10681068
// the query.
@@ -1101,10 +1101,10 @@ public void testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing() {
11011101
// Update the view, but don't mark the view synced.
11021102
Assert.assertEquals(
11031103
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
1104-
udpateViews(targetId, /* fromCache=*/ false);
1104+
udpateViews(targetId, /* synced=*/ true);
11051105

11061106
// The query is marked limbo-free only when we mark the view synced.
1107-
udpateViews(targetId, /* fromCache=*/ false);
1107+
udpateViews(targetId, /* synced=*/ true);
11081108
Assert.assertNotEquals(
11091109
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
11101110

@@ -1134,7 +1134,7 @@ public void testQueriesIncludeLocallyModifiedDocuments() {
11341134
asList(targetId),
11351135
emptyList()));
11361136
applyRemoteEvent(noChangeEvent(targetId, 10));
1137-
udpateViews(targetId, /* fromCache= */ false);
1137+
udpateViews(targetId, /* synced= */ true);
11381138

11391139
// Execute the query based on the RemoteEvent.
11401140
executeQuery(query);
@@ -1171,7 +1171,7 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
11711171
asList(targetId),
11721172
emptyList()));
11731173
applyRemoteEvent(noChangeEvent(targetId, 10));
1174-
udpateViews(targetId, /* fromCache=*/ false);
1174+
udpateViews(targetId, /* synced=*/ true);
11751175
releaseQuery(filteredQuery);
11761176

11771177
// Start another query and add more matching documents to the collection.
@@ -1213,7 +1213,7 @@ public void testQueriesFilterDocumentsThatNoLongerMatch() {
12131213
asList(targetId),
12141214
emptyList()));
12151215
applyRemoteEvent(noChangeEvent(targetId, 10));
1216-
udpateViews(targetId, /* fromCache=*/ false);
1216+
udpateViews(targetId, /* synced=*/ true);
12171217
releaseQuery(filteredQuery);
12181218

12191219
// Modify one of the documents to no longer match while the filtered query is inactive.

0 commit comments

Comments
 (0)