Replace flatten->buildHierarchy with correct conversion
Currently when converting from ITree to ISnapshotTree, the tree is first flattened into a git ITree, and then an ISnapshotTree is built from that. The problem is that original ids in the ITree (tree nodes) will be lost in the git ITree. All ids in the resulting tree will be empty string for trees (also should be null if falsey) or the sha for other nodes.
I think ISnapshotTree should not have IDs (on interface). Runtime never uses IDs, and there is no storage API to leverage them (no way to load partial trees, only full snapshot tree, i.e. commit tree). The code in R11S that does need IDs could use another interface (let's call it ISnapshotTreeEx for now), and usage of this interface would be self-contained in R11 layers.
When summarizing, we use handle + path as a way to reuse blobs / trees, I think that's the way it will stay forever, to keep the efficiency of snapshotting (not fetching resulting tree from runtime).
That all said, any clue why buildSnapshotTree() has to flatten first to build ISnapshotTree? Why don't we convert it as-is, node by node? Is this only due to potential reuse of sub-trees? Glancing through usage, it's used either for attaching DDS/Data store, or capturing in-memory snapshot of container, or in helper drivers.
Here is the part where my logic above partially breaks: DocumentStorageService.getSnapshotTree is using buildHierarchy() and relies on IDs to be there (it does not use flatten, its source of truth is git structure). Then, there are 3 copies of getIdFromPathCore() in server code that rely on IDs to be in there. That's the only path I see (after making code changes and seeing where build breaks) where IDs matter.
I think we should leave buildHierarchy() as is, but
- change buildSnapshotTree() to be direct conversion (i.e. not using git's ITree intermidiate) and not care about IDs. This will remove the need for flatten() API to exist.
- Change ODSP driver not depend on similar structure (they have their own ITree definition used in ODSP snapshots) - I'm working on changing file format there, so that code will be gone at some point (I hope).
With that, I believe we could fork ISnapshotTree into two interfaces - one for runtime (no ids), and one for R11S (using IDs).
What do you think?
Whatever we do, can we not encode & decode base64 buffers in flattenCore() and start returning ArrayBufferLike? Otherwise we do 2-3 conversions (2 in flattenCore, and one in consumer, but minimum is 2). Such a waste of resources.
This PR has been automatically marked as stale because it has had no activity for 60 days. It will be closed if no further activity occurs within 8 days of this comment. Thank you for your contributions to Fluid Framework!