use of com.google.firebase.firestore.local.LocalViewChanges in project firebase-android-sdk by firebase.
the class TestUtil method viewChanges.
public static LocalViewChanges viewChanges(int targetId, boolean fromCache, List<String> addedKeys, List<String> removedKeys) {
ImmutableSortedSet<DocumentKey> added = DocumentKey.emptyKeySet();
for (String keyPath : addedKeys) {
added = added.insert(key(keyPath));
}
ImmutableSortedSet<DocumentKey> removed = DocumentKey.emptyKeySet();
for (String keyPath : removedKeys) {
removed = removed.insert(key(keyPath));
}
return new LocalViewChanges(targetId, fromCache, added, removed);
}
use of com.google.firebase.firestore.local.LocalViewChanges in project firebase-android-sdk by firebase.
the class SyncEngine method emitNewSnapsAndNotifyLocalStore.
/**
* Computes a new snapshot from the changes and calls the registered callback with the new
* snapshot.
*/
private void emitNewSnapsAndNotifyLocalStore(ImmutableSortedMap<DocumentKey, Document> changes, @Nullable RemoteEvent remoteEvent) {
List<ViewSnapshot> newSnapshots = new ArrayList<>();
List<LocalViewChanges> documentChangesInAllViews = new ArrayList<>();
for (Map.Entry<Query, QueryView> entry : queryViewsByQuery.entrySet()) {
QueryView queryView = entry.getValue();
View view = queryView.getView();
View.DocumentChanges viewDocChanges = view.computeDocChanges(changes);
if (viewDocChanges.needsRefill()) {
// The query has a limit and some docs were removed/updated, so we need to re-run the query
// against the local store to make sure we didn't lose any good docs that had been past the
// limit.
QueryResult queryResult = localStore.executeQuery(queryView.getQuery(), /* usePreviousResults= */
false);
viewDocChanges = view.computeDocChanges(queryResult.getDocuments(), viewDocChanges);
}
TargetChange targetChange = remoteEvent == null ? null : remoteEvent.getTargetChanges().get(queryView.getTargetId());
ViewChange viewChange = queryView.getView().applyChanges(viewDocChanges, targetChange);
updateTrackedLimboDocuments(viewChange.getLimboChanges(), queryView.getTargetId());
if (viewChange.getSnapshot() != null) {
newSnapshots.add(viewChange.getSnapshot());
LocalViewChanges docChanges = LocalViewChanges.fromViewSnapshot(queryView.getTargetId(), viewChange.getSnapshot());
documentChangesInAllViews.add(docChanges);
}
}
syncEngineListener.onViewSnapshots(newSnapshots);
localStore.notifyLocalViewChanges(documentChangesInAllViews);
}
Aggregations