Every folder creation or file upload rewrites the entire user tree to the KV store. For a tree with 10,000 nodes this is tens of KB per operation. Per-node storage with parent-keyed reads is closer to how a real filesystem works.
Current state:
set_kv(username + " ROOT", root.to_json()) serializes the whole tree on every write.
Proposed implementation:
- New KV layout:
"<user>:node:<path_hash>" → node JSON (one node per key), plus "<user>:node:<path>:children" → sorted list of child names. Or: "<user>:tree" still exists as a small index of root-level names only.
/create-folder writes one new key for the folder + updates the parent's children list (two writes instead of one, both small).
/delete removes the subtree (N writes) but is still faster in the common case of small deletes.
- Write an offline migration reading the old JSON blob into the new layout.
- Trade-off: listing a large folder is now N reads; add a single "listing" key per folder to compensate.
Files likely affected:
backend/node.py (add save/load methods)
backend/RSDB_kv_service.py (no changes needed — it's still KV)
app.py (every mutating route)
scripts/migrate_tree_to_per_node.py (new)
- Tests.
Acceptance criteria:
- Average bytes written per folder operation drops from ~O(tree) to O(1).
- Round-trip test: old format migrated, all nodes readable, tree structure identical.
- New users use the per-node layout from first write.
Every folder creation or file upload rewrites the entire user tree to the KV store. For a tree with 10,000 nodes this is tens of KB per operation. Per-node storage with parent-keyed reads is closer to how a real filesystem works.
Current state:
set_kv(username + " ROOT", root.to_json())serializes the whole tree on every write.Proposed implementation:
"<user>:node:<path_hash>"→ node JSON (one node per key), plus"<user>:node:<path>:children"→ sorted list of child names. Or:"<user>:tree"still exists as a small index of root-level names only./create-folderwrites one new key for the folder + updates the parent's children list (two writes instead of one, both small)./deleteremoves the subtree (N writes) but is still faster in the common case of small deletes.Files likely affected:
backend/node.py(addsave/loadmethods)backend/RSDB_kv_service.py(no changes needed — it's still KV)app.py(every mutating route)scripts/migrate_tree_to_per_node.py(new)Acceptance criteria: