in src/main/java/com/google/firebase/database/core/WriteTree.java [258:314]
public Node calcCompleteEventCache(
final Path treePath,
Node completeServerCache,
final List<Long> writeIdsToExclude,
final boolean includeHiddenWrites) {
if (writeIdsToExclude.isEmpty() && !includeHiddenWrites) {
Node shadowingNode = this.visibleWrites.getCompleteNode(treePath);
if (shadowingNode != null) {
return shadowingNode;
} else {
CompoundWrite subMerge = this.visibleWrites.childCompoundWrite(treePath);
if (subMerge.isEmpty()) {
return completeServerCache;
} else if (completeServerCache == null && !subMerge.hasCompleteWrite(Path.getEmptyPath())) {
// We wouldn't have a complete snapshot, since there's no underlying data and
// no complete
// shadow
return null;
} else {
Node layeredCache;
if (completeServerCache != null) {
layeredCache = completeServerCache;
} else {
layeredCache = EmptyNode.Empty();
}
return subMerge.apply(layeredCache);
}
}
} else {
CompoundWrite merge = this.visibleWrites.childCompoundWrite(treePath);
if (!includeHiddenWrites && merge.isEmpty()) {
return completeServerCache;
} else {
// If the server cache is null, and we don't have a complete cache, we need to
// return null
if (!includeHiddenWrites
&& completeServerCache == null
&& !merge.hasCompleteWrite(Path.getEmptyPath())) {
return null;
} else {
Predicate<UserWriteRecord> filter =
new Predicate<UserWriteRecord>() {
@Override
public boolean evaluate(UserWriteRecord write) {
return (write.isVisible() || includeHiddenWrites)
&& (!writeIdsToExclude.contains(write.getWriteId()))
&& (write.getPath().contains(treePath) || treePath.contains(write.getPath()));
}
};
Node layeredCache;
CompoundWrite mergeAtPath = WriteTree.layerTree(this.allWrites, filter, treePath);
layeredCache = completeServerCache != null ? completeServerCache : EmptyNode.Empty();
return mergeAtPath.apply(layeredCache);
}
}
}
}