From fb007920ee8e8e12c9cbc52399c94a16882e2016 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Thu, 19 Mar 2026 10:23:23 +0100 Subject: [PATCH] Fix history_tree_backup bloat: strip snapshot data from backups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- main.py | 9 +++++++++ tab_timeline_ng.py | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index e9ed3d6..d0ba139 100644 --- a/main.py +++ b/main.py @@ -297,6 +297,10 @@ def index(): if tree and isinstance(tree, dict): for node in tree.get('nodes', {}).values(): 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.last_mtime = fp.stat().st_mtime if fp.exists() else 0 pane_state.loaded_file = str(fp) @@ -337,6 +341,11 @@ def index(): if tree and isinstance(tree, dict): for node in tree.get('nodes', {}).values(): 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.last_mtime = fp.stat().st_mtime if fp.exists() else 0 state.loaded_file = str(fp) diff --git a/tab_timeline_ng.py b/tab_timeline_ng.py index 6dffd32..b0b82d4 100644 --- a/tab_timeline_ng.py +++ b/tab_timeline_ng.py @@ -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.""" if 'history_tree_backup' not in data: 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:] # Save deleted node parents before removal (needed for branch re-pointing) deleted_parents = {}