Fix RAM leak: strip history snapshots from memory, load on demand
History tree nodes stored full data snapshots in memory (5-50MB each), accumulating with every save. Now: - New `history_snapshots` DB table stores node data separately - `save_history_tree` and `sync_to_db` extract snapshots before saving - In-memory tree nodes only hold metadata (id, parent, note, timestamp) - Restore and preview load snapshots from DB on demand - `save_and_snap` uses json roundtrip instead of deepcopy (1 copy not 2) - `_src_cache` moved to AppState, cleared on file switch - `strip_snapshots()` method on HistoryTree for explicit cleanup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,11 @@ class HistoryTree:
|
||||
return self.nodes[node_id]["data"]
|
||||
return None
|
||||
|
||||
def strip_snapshots(self) -> None:
|
||||
"""Remove snapshot data from all nodes to free memory."""
|
||||
for node in self.nodes.values():
|
||||
node.pop("data", None)
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
return {"nodes": self.nodes, "branches": self.branches, "head_id": self.head_id}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user