Skip to content

Remove newly redundant synced flag #771

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
Show file tree
Hide file tree
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 @@ -117,7 +117,6 @@ public static QuerySnapshot querySnapshot(
documentChanges,
isFromCache,
mutatedKeys,
/* synced= */ false,
/* didSyncStateChange= */ true,
/* excludesMetadataChanges= */ false);
return new QuerySnapshot(query(path), viewSnapshot, FIRESTORE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void onViewSnapshot(ViewSnapshot newSnapshot) {
documentChanges,
newSnapshot.isFromCache(),
newSnapshot.getMutatedKeys(),
newSnapshot.isSynced(),
newSnapshot.didSyncStateChange(),
/* excludesMetadataChanges= */ true);
}
Expand Down Expand Up @@ -159,7 +158,6 @@ private void raiseInitialEvent(ViewSnapshot snapshot) {
snapshot.getDocuments(),
snapshot.getMutatedKeys(),
snapshot.isFromCache(),
snapshot.isSynced(),
snapshot.excludesMetadataChanges());
raisedInitialEvent = true;
listener.onEvent(snapshot, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ public ViewChange applyChanges(DocumentChanges docChanges, TargetChange targetCh
viewChanges,
fromCache,
docChanges.mutatedKeys,
synced,
syncStatedChanged,
/* excludesMetadataChanges= */ false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public enum SyncState {
private final List<DocumentViewChange> changes;
private final boolean isFromCache;
private final ImmutableSortedSet<DocumentKey> mutatedKeys;
private final boolean synced;
private final boolean didSyncStateChange;
private boolean excludesMetadataChanges;

Expand All @@ -48,7 +47,6 @@ public ViewSnapshot(
List<DocumentViewChange> changes,
boolean isFromCache,
ImmutableSortedSet<DocumentKey> mutatedKeys,
boolean synced,
boolean didSyncStateChange,
boolean excludesMetadataChanges) {
this.query = query;
Expand All @@ -57,7 +55,6 @@ public ViewSnapshot(
this.changes = changes;
this.isFromCache = isFromCache;
this.mutatedKeys = mutatedKeys;
this.synced = synced;
this.didSyncStateChange = didSyncStateChange;
this.excludesMetadataChanges = excludesMetadataChanges;
}
Expand All @@ -68,7 +65,6 @@ public static ViewSnapshot fromInitialDocuments(
DocumentSet documents,
ImmutableSortedSet<DocumentKey> mutatedKeys,
boolean fromCache,
boolean synced,
boolean excludesMetadataChanges) {
List<DocumentViewChange> viewChanges = new ArrayList<>();
for (Document doc : documents) {
Expand All @@ -81,7 +77,6 @@ public static ViewSnapshot fromInitialDocuments(
viewChanges,
fromCache,
mutatedKeys,
synced,
/* didSyncStateChange= */ true,
excludesMetadataChanges);
}
Expand All @@ -90,10 +85,6 @@ public Query getQuery() {
return query;
}

public boolean isSynced() {
return synced;
}

public DocumentSet getDocuments() {
return documents;
}
Expand Down Expand Up @@ -140,9 +131,6 @@ public final boolean equals(Object o) {
if (isFromCache != that.isFromCache) {
return false;
}
if (synced != that.synced) {
return false;
}
if (didSyncStateChange != that.didSyncStateChange) {
return false;
}
Expand Down Expand Up @@ -172,7 +160,6 @@ public int hashCode() {
result = 31 * result + changes.hashCode();
result = 31 * result + mutatedKeys.hashCode();
result = 31 * result + (isFromCache ? 1 : 0);
result = 31 * result + (synced ? 1 : 0);
result = 31 * result + (didSyncStateChange ? 1 : 0);
result = 31 * result + (excludesMetadataChanges ? 1 : 0);
return result;
Expand All @@ -192,8 +179,6 @@ public String toString() {
+ isFromCache
+ ", mutatedKeys="
+ mutatedKeys.size()
+ ", synced="
+ synced
+ ", didSyncStateChange="
+ didSyncStateChange
+ ", excludesMetadataChanges="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public void notifyLocalViewChanges(List<LocalViewChanges> viewChanges) {
}
localViewReferences.removeReferences(removed, targetId);

if (viewChange.isSynced()) {
if (!viewChange.isFromCache()) {
QueryData queryData = targetIds.get(targetId);
hardAssert(
queryData != null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ public static LocalViewChanges fromViewSnapshot(int targetId, ViewSnapshot snaps
}
}

return new LocalViewChanges(targetId, snapshot.isSynced(), addedKeys, removedKeys);
return new LocalViewChanges(targetId, snapshot.isFromCache(), addedKeys, removedKeys);
}

private final int targetId;
private final boolean synced;
private final boolean fromCache;

private final ImmutableSortedSet<DocumentKey> added;
private final ImmutableSortedSet<DocumentKey> removed;

public LocalViewChanges(
int targetId,
boolean synced,
boolean fromCache,
ImmutableSortedSet<DocumentKey> added,
ImmutableSortedSet<DocumentKey> removed) {
this.targetId = targetId;
this.synced = synced;
this.fromCache = fromCache;
this.added = added;
this.removed = removed;
}
Expand All @@ -73,8 +73,8 @@ public int getTargetId() {
return targetId;
}

public boolean isSynced() {
return synced;
public boolean isFromCache() {
return fromCache;
}

public ImmutableSortedSet<DocumentKey> getAdded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public static QuerySnapshot querySnapshot(
documentChanges,
isFromCache,
mutatedKeys,
/* synced= */ false,
/* didSyncStateChange= */ true,
/* excludesMetadataChanges= */ false);
return new QuerySnapshot(query(path), viewSnapshot, FIRESTORE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public void testIncludeMetadataChanges() {
documentChanges,
/*isFromCache=*/ false,
/*mutatedKeys=*/ keySet(),
/*isSynced=*/ true,
/*didSyncStateChange=*/ true,
/* excludesMetadataChanges= */ false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public void testRaisesCollectionEvents() {
asList(change1, change4),
snap2.isFromCache(),
snap2.getMutatedKeys(),
/* synced= */ false,
/* didSyncStateChange= */ true,
/* excludesMetadataChanges= */ false);
assertEquals(asList(snap2Prime), otherAccum);
Expand Down Expand Up @@ -266,7 +265,6 @@ public void testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChang
asList(),
snap4.isFromCache(),
snap4.getMutatedKeys(),
snap4.isSynced(),
snap4.didSyncStateChange(),
/* excludeMetadataChanges= */ true); // This test excludes document metadata changes

Expand Down Expand Up @@ -308,7 +306,6 @@ public void testMetadataOnlyDocumentChangesAreFilteredOut() {
asList(change3),
snap2.isFromCache(),
snap2.getMutatedKeys(),
snap2.isSynced(),
snap2.didSyncStateChange(),
/* excludesMetadataChanges= */ true);
assertEquals(
Expand Down Expand Up @@ -351,7 +348,6 @@ public void testWillWaitForSyncIfOnline() {
asList(change1, change2),
/* isFromCache= */ false,
snap3.getMutatedKeys(),
/* synced= */ true,
/* didSyncStateChange= */ true,
/* excludesMetadataChanges= */ true);
assertEquals(asList(expectedSnapshot), events);
Expand Down Expand Up @@ -390,7 +386,6 @@ public void testWillRaiseInitialEventWhenGoingOffline() {
asList(change1),
/* isFromCache= */ true,
snap1.getMutatedKeys(),
snap1.isSynced(),
/* didSyncStateChange= */ true,
/* excludesMetadataChanges= */ true);
ViewSnapshot expectedSnapshot2 =
Expand All @@ -401,7 +396,6 @@ public void testWillRaiseInitialEventWhenGoingOffline() {
asList(change2),
/* isFromCache= */ true,
snap2.getMutatedKeys(),
snap2.isSynced(),
/* didSyncStateChange= */ false,
/* excludesMetadataChanges= */ true);
assertEquals(asList(expectedSnapshot1, expectedSnapshot2), events);
Expand Down Expand Up @@ -429,7 +423,6 @@ public void testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs() {
asList(),
/* isFromCache= */ true,
snap1.getMutatedKeys(),
snap1.isSynced(),
/* didSyncStateChange= */ true,
/* excludesMetadataChanges= */ true);
assertEquals(asList(expectedSnapshot), events);
Expand All @@ -456,7 +449,6 @@ public void testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs() {
asList(),
/* isFromCache= */ true,
snap1.getMutatedKeys(),
snap1.isSynced(),
/* didSyncStateChange= */ true,
/* excludesMetadataChanges= */ true);
assertEquals(asList(expectedSnapshot), events);
Expand All @@ -470,7 +462,6 @@ private ViewSnapshot applyExpectedMetadata(ViewSnapshot snap, MetadataChanges me
snap.getChanges(),
snap.isFromCache(),
snap.getMutatedKeys(),
snap.isSynced(),
snap.didSyncStateChange(),
MetadataChanges.EXCLUDE.equals(metadata));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public void testConstructor() {
List<DocumentViewChange> changes =
Arrays.asList(DocumentViewChange.create(Type.ADDED, doc("c/foo", 1, map())));
ImmutableSortedSet<DocumentKey> mutatedKeys = keySet(key("c/foo"));
boolean synced = true;
boolean fromCache = true;
boolean hasPendingWrites = true;
boolean syncStateChanges = true;
Expand All @@ -59,7 +58,6 @@ public void testConstructor() {
changes,
fromCache,
mutatedKeys,
synced,
syncStateChanges,
excludesMetadataChanges);

Expand All @@ -69,7 +67,6 @@ public void testConstructor() {
assertEquals(changes, snapshot.getChanges());
assertEquals(fromCache, snapshot.isFromCache());
assertEquals(mutatedKeys, snapshot.getMutatedKeys());
assertEquals(synced, snapshot.isSynced());
assertEquals(hasPendingWrites, snapshot.hasPendingWrites());
assertEquals(syncStateChanges, snapshot.didSyncStateChange());
assertEquals(excludesMetadataChanges, snapshot.excludesMetadataChanges());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void testKeepsTrackOfLimboDocuments() {
}

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

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

// Add doc1 to the backend's result set.
change =
view.applyChanges(
viewDocChanges, targetChange(ByteString.EMPTY, true, asList(doc1), null, null));
assertTrue(change.getSnapshot().isSynced());
assertFalse(change.getSnapshot().isFromCache());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ private void notifyLocalViewChanges(LocalViewChanges changes) {
localStore.notifyLocalViewChanges(asList(changes));
}

private void udpateViews(int targetId, boolean synced) {
notifyLocalViewChanges(viewChanges(targetId, synced, asList(), asList()));
private void udpateViews(int targetId, boolean fromCache) {
notifyLocalViewChanges(viewChanges(targetId, fromCache, asList(), asList()));
}

private void acknowledgeMutation(long documentVersion, @Nullable Object transformResult) {
Expand Down Expand Up @@ -311,7 +311,7 @@ public void testHandlesSetMutationThenAckThenRelease() {
allocateQuery(query);

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

assertChanged(doc("foo/bar", 0, map("foo", "bar"), Document.DocumentState.LOCAL_MUTATIONS));
assertContains(doc("foo/bar", 0, map("foo", "bar"), Document.DocumentState.LOCAL_MUTATIONS));
Expand Down Expand Up @@ -832,15 +832,15 @@ public void testPinsDocumentsInTheLocalView() {
assertContains(doc("foo/baz", 0, map("foo", "baz"), Document.DocumentState.LOCAL_MUTATIONS));

notifyLocalViewChanges(
viewChanges(2, /* synced= */ false, asList("foo/bar", "foo/baz"), emptyList()));
viewChanges(2, /* fromCache= */ false, asList("foo/bar", "foo/baz"), emptyList()));
applyRemoteEvent(updateRemoteEvent(doc("foo/bar", 1, map("foo", "bar")), none, two));
applyRemoteEvent(updateRemoteEvent(doc("foo/baz", 2, map("foo", "baz")), two, none));
acknowledgeMutation(2);
assertContains(doc("foo/bar", 1, map("foo", "bar")));
assertContains(doc("foo/baz", 2, map("foo", "baz")));

notifyLocalViewChanges(
viewChanges(2, /* synced= */ false, emptyList(), asList("foo/bar", "foo/baz")));
viewChanges(2, /* fromCache= */ false, emptyList(), asList("foo/bar", "foo/baz")));
releaseQuery(query);

assertNotContains("foo/bar");
Expand Down Expand Up @@ -1062,7 +1062,7 @@ public void testUsesTargetMappingToExecuteQueries() {
asList(targetId),
emptyList()));
applyRemoteEvent(noChangeEvent(targetId, 10));
udpateViews(targetId, /* synced= */ true);
udpateViews(targetId, /* fromCache= */ false);

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

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

Expand Down Expand Up @@ -1134,7 +1134,7 @@ public void testQueriesIncludeLocallyModifiedDocuments() {
asList(targetId),
emptyList()));
applyRemoteEvent(noChangeEvent(targetId, 10));
udpateViews(targetId, /* synced= */ true);
udpateViews(targetId, /* fromCache= */ false);

// Execute the query based on the RemoteEvent.
executeQuery(query);
Expand Down Expand Up @@ -1171,7 +1171,7 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
asList(targetId),
emptyList()));
applyRemoteEvent(noChangeEvent(targetId, 10));
udpateViews(targetId, /* synced=*/ true);
udpateViews(targetId, /* fromCache=*/ false);
releaseQuery(filteredQuery);

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

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