Fix get_knowledge_graph query slow problem for PostgreSQL AGE

This commit is contained in:
yangdx
2025-04-24 08:40:06 +08:00
parent e19d5fa9be
commit ffbe2a0c5d

View File

@@ -1849,9 +1849,8 @@ class PGGraphStorage(BaseGraphStorage):
else:
strip_label = self._normalize_node_id(node_label)
count_query = f"""SELECT * FROM cypher('{self.graph_name}', $$
MATCH (n:base {{entity_id: "{strip_label}"}})
OPTIONAL MATCH p = (n)-[*..{max_depth}]-()
RETURN count(nodes(p)) AS total_nodes
MATCH (n:base {{entity_id: "{strip_label}"}})-[r]-()
RETURN count(r) AS total_nodes
$$) AS (total_nodes bigint)"""
count_result = await self._query(count_query)