fix: add missing self._lock to query_relationship, timeline, stats in KnowledgeGraph

This commit is contained in:
shafdev
2026-04-15 00:33:58 +05:30
parent a3f4674963
commit 1fa0e57d74
+4 -1
View File
@@ -260,7 +260,6 @@ class KnowledgeGraph:
def query_relationship(self, predicate: str, as_of: str = None):
"""Get all triples with a given relationship type."""
pred = predicate.lower().replace(" ", "_")
conn = self._conn()
query = """
SELECT t.*, s.name as sub_name, o.name as obj_name
FROM triples t
@@ -274,6 +273,8 @@ class KnowledgeGraph:
params.extend([as_of, as_of])
results = []
with self._lock:
conn = self._conn()
for row in conn.execute(query, params).fetchall():
results.append(
{
@@ -289,6 +290,7 @@ class KnowledgeGraph:
def timeline(self, entity_name: str = None):
"""Get all facts in chronological order, optionally filtered by entity."""
with self._lock:
conn = self._conn()
if entity_name:
eid = self._entity_id(entity_name)
@@ -329,6 +331,7 @@ class KnowledgeGraph:
# ── Stats ─────────────────────────────────────────────────────────────
def stats(self):
with self._lock:
conn = self._conn()
entities = conn.execute("SELECT COUNT(*) as cnt FROM entities").fetchone()["cnt"]
triples = conn.execute("SELECT COUNT(*) as cnt FROM triples").fetchone()["cnt"]