Merge pull request #884 from shafdev/fix/kg-missing-lock
fix: add missing self._lock to query_relationship, timeline, and stats in KnowledgeGraph
This commit is contained in:
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user