From 21f2248a3c41dae53ba596121ef83413a7c6cb8f Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Tue, 7 Apr 2026 17:21:37 -0300 Subject: [PATCH] fix: enable SQLite WAL mode and add consistent LIMIT to KG timeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Enable WAL journal mode in _conn() for better concurrent read performance and reduced SQLITE_BUSY risk - Add LIMIT 100 to entity-filtered timeline query (was unbounded, while global timeline already had LIMIT 100) Findings: #8 (HIGH — no WAL mode), #22 (LOW — inconsistent limits) Includes test infrastructure from PR #131. 92 tests pass. --- mempalace/knowledge_graph.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mempalace/knowledge_graph.py b/mempalace/knowledge_graph.py index a2f8b54..226c92d 100644 --- a/mempalace/knowledge_graph.py +++ b/mempalace/knowledge_graph.py @@ -87,7 +87,9 @@ class KnowledgeGraph: conn.close() def _conn(self): - return sqlite3.connect(self.db_path, timeout=10) + conn = sqlite3.connect(self.db_path, timeout=10) + conn.execute("PRAGMA journal_mode=WAL") + return conn def _entity_id(self, name: str) -> str: return name.lower().replace(" ", "_").replace("'", "") @@ -284,6 +286,7 @@ class KnowledgeGraph: JOIN entities o ON t.object = o.id WHERE (t.subject = ? OR t.object = ?) ORDER BY t.valid_from ASC NULLS LAST + LIMIT 100 """, (eid, eid), ).fetchall()