Fix history_tree_backup bloat: strip snapshot data from backups
The history_tree_backup (created by _delete_nodes) was storing full snapshot data in every backed-up node — 185MB+ per backup entry. This caused the JSON file to re-bloat to 300MB on every save. Now: - _delete_nodes backs up tree metadata only (no snapshot data) - Load paths strip snapshot data from existing backup entries - Prevents both disk and RAM bloat from backup accumulation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -297,6 +297,10 @@ def index():
|
|||||||
if tree and isinstance(tree, dict):
|
if tree and isinstance(tree, dict):
|
||||||
for node in tree.get('nodes', {}).values():
|
for node in tree.get('nodes', {}).values():
|
||||||
node.pop('data', None)
|
node.pop('data', None)
|
||||||
|
for backup in data.get('history_tree_backup', []):
|
||||||
|
if isinstance(backup, dict):
|
||||||
|
for node in backup.get('nodes', {}).values():
|
||||||
|
node.pop('data', None)
|
||||||
pane_state.data_cache = data
|
pane_state.data_cache = data
|
||||||
pane_state.last_mtime = fp.stat().st_mtime if fp.exists() else 0
|
pane_state.last_mtime = fp.stat().st_mtime if fp.exists() else 0
|
||||||
pane_state.loaded_file = str(fp)
|
pane_state.loaded_file = str(fp)
|
||||||
@@ -337,6 +341,11 @@ def index():
|
|||||||
if tree and isinstance(tree, dict):
|
if tree and isinstance(tree, dict):
|
||||||
for node in tree.get('nodes', {}).values():
|
for node in tree.get('nodes', {}).values():
|
||||||
node.pop('data', None)
|
node.pop('data', None)
|
||||||
|
# Strip snapshot data from history_tree_backup to prevent RAM/disk bloat
|
||||||
|
for backup in data.get('history_tree_backup', []):
|
||||||
|
if isinstance(backup, dict):
|
||||||
|
for node in backup.get('nodes', {}).values():
|
||||||
|
node.pop('data', None)
|
||||||
state.data_cache = data
|
state.data_cache = data
|
||||||
state.last_mtime = fp.stat().st_mtime if fp.exists() else 0
|
state.last_mtime = fp.stat().st_mtime if fp.exists() else 0
|
||||||
state.loaded_file = str(fp)
|
state.loaded_file = str(fp)
|
||||||
|
|||||||
+5
-1
@@ -17,7 +17,11 @@ def _delete_nodes(htree, data, file_path, node_ids, state=None):
|
|||||||
"""Delete nodes with backup, branch cleanup, re-parenting, and head fallback."""
|
"""Delete nodes with backup, branch cleanup, re-parenting, and head fallback."""
|
||||||
if 'history_tree_backup' not in data:
|
if 'history_tree_backup' not in data:
|
||||||
data['history_tree_backup'] = []
|
data['history_tree_backup'] = []
|
||||||
data['history_tree_backup'].append(json.loads(json.dumps(htree.to_dict())))
|
# Back up tree metadata only (no snapshot data) to avoid bloating JSON
|
||||||
|
backup = json.loads(json.dumps(htree.to_dict()))
|
||||||
|
for node in backup.get('nodes', {}).values():
|
||||||
|
node.pop('data', None)
|
||||||
|
data['history_tree_backup'].append(backup)
|
||||||
data['history_tree_backup'] = data['history_tree_backup'][-10:]
|
data['history_tree_backup'] = data['history_tree_backup'][-10:]
|
||||||
# Save deleted node parents before removal (needed for branch re-pointing)
|
# Save deleted node parents before removal (needed for branch re-pointing)
|
||||||
deleted_parents = {}
|
deleted_parents = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user