fix(graph): cap get_all_edges to 5000 edges to prevent unbounded RAM growth

This commit is contained in:
Ubuntu 2026-04-26 14:50:21 +00:00
parent d09ee23cd3
commit 656a3d7d5c
1 changed files with 7 additions and 3 deletions

View File

@ -392,13 +392,17 @@ class GraphitiBackend(GraphBackend):
})
return nodes
def get_all_edges(self, graph_id: str) -> List[Dict[str, Any]]:
def get_all_edges(self, graph_id: str, max_items: int = 5000) -> List[Dict[str, Any]]:
results = _run_async(
self._client.driver.execute_query(
"MATCH (s)-[r]->(t) WHERE r.group_id = $gid RETURN s, r, t",
params={"gid": graph_id},
"MATCH (s)-[r]->(t) WHERE r.group_id = $gid RETURN s, r, t LIMIT $limit",
params={"gid": graph_id, "limit": max_items},
)
)
if len(results.records) >= max_items:
logger.warning(
f"get_all_edges: result truncated at {max_items} edges for graph {graph_id}"
)
edges = []
for record in results.records:
r = record["r"]